php / mysql

Permabanned
Joined
19 Apr 2006
Posts
2,333
Location
West Yorkshire
Does this look right?

Code:
<?php
$names = @mysql_query( 'SELECT name FROM sed_1car1_branches' );
?>

<table>
	<tr>
		<td>
			<ul>
				<? echo('<li><a href="#' . $names . '">' . $names . '</a></li>'); ?>
</ul>
		</td>
	<tr>
</table>

I am n00b and the php stuff.
 
Last edited:
thanks for the help, it appears my code was all screwed up completely so I redid it like this:

Code:
$query="SELECT * FROM sed_1car1_branches ORDER BY name ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;


echo "<ul>";
while ($i < $num) {

$name=mysql_result($result,$i,"name");

echo "<li><a href='#$name'>$name</a></li>";
$i++;
}
echo "</ul>";

As I say I am a bit of a n00b at all this, but am getting there.

I would like to change it now, so instead of outputting a huge list, it instead gives you a drop down list with all the names in.

How do go I about that?
 
marc2003 said:
<snip>

tidied it up a bit. :)

Thanks dude, that works a treat.

However I want it so when one of the names is selected it then refreshes the page and displays the rest of the info?
 
Almost marc :P I appreciate the help though.

Let me explain properly what I am doing, I am trying to make a staff intranet and am using the Seditio CMS system, which is working great.

Now I need to convert some spreadsheets and documents into web friendly pages and forms.

This page in particular is instead of a spreadsheet that contains all our branch information.

So what I am wanting is for them to come to this page, select the branch name they are looking for, then the page refreshes (still with the select box at the top) and displays the info for the branch they selected.

It has to stay on the one page, not multiple pages and it cant contain naked html (as it needs to be encapsulated in php) as the CMS allows parsing of html or PHP not both :S
 
Is it not possible to do this (and I appologise for the daft psuedo code type writing).

if VALUE is set
THEN
display branch_info
ELSE
display select_box
IF SUBMIT
THEN
VALUE = branch_name

if that makes any sense?
 
Thanks again Marc, it is genuinely appreciated.

I had to play around a bit with the code, but this is how I got it in the end;

Code:
echo '
<form action="" method="post" name="f">
<select name="branch"> ';


$result = mysql_query("SELECT * FROM sed_1car1_branches ORDER BY name ASC");

while($row = mysql_fetch_assoc($result)) {
    $name = $row['name'];
    if($_POST['branch'] == $name)  { 
		$bname = $row['name'];
		$baddress = $row['address']; 
		$bpcode = $row['post_code']; 
		$bcode = $row['code']; 
		$btel_front = $row['tel_front']; 
		$btel_back = $row['tel_back']; 
		$bfax = $row['fax']; 
		$bmobile = $row['mobile']; 
		$bmanager = $row['manager']; 
		$bemail = $row['email'];
 }
else {
    echo '<option value='.$name.'>'.$name.'</option>' ;} 
}

echo '
</select>
<input type="submit" name="go" value="Go!">
</form>
<br /> ';

if ($baddress) {
echo " <table>
			<tr>
				<td colspan='2'><strong>$bname ( $bcode )</strong></td>
			</tr>
			<tr>
				<td><strong>Manager:</strong></td>
				<td>$bmanager</td>
			</tr>
			<tr>
				<td><strong>Address:</strong></td>
				<td> $baddress , $bpcode</td>
			</tr>
			<tr>
				<td><strong>Front Line:</strong></td>
				<td>$btel_front</td>
			</tr>
			<tr>
				<td><strong>Back Line:</strong></td>
				<td>$btel_back</td>
			</tr>
			<tr>
				<td><strong>Mobile:</strong></td>
				<td>$bmobile</td>
			</tr>
			<tr>
				<td><strong>Fax:</strong></td>
				<td>$bfax</td>
			</tr>
			<tr>
				<td><strong>E-mail:</strong></td>
				<td><a href='mailto:$bemail'>$bemail</a></td>
				</tr>
			</table> ";
}

The only thing I can't do now is make it so, when a branch is selected it's name stays in the selection box when the page refreshes, instead it reverts back to the first in the list.

Is this possible?
 
Absolutely fantastic marc :) \o/ Is working like a treat !

final thing though I promise.

Any branch name ($name) with a space in it like "Head Office" or "Milton Keynes" and it doesnt work, it takes you back to the selection box with no info for that branch.

If I select "Manchester Airport" or "Manchester Central" then it takes me to the details of the "Manchester" site, so it looks like it isnt taking the second word in to account.
 
marc2003 said:
you'll need to add double quotes around the value....

Code:
echo '<option value="'.$name.'"';


Now I deffinitely owe you a beer or 10 :)

Thanks all, but especially your good self Mr Marc, no doubt I will be back with more questions.
 
Back
Top Bottom