Topshed Posted November 29, 2007 Share Posted November 29, 2007 I have a strange problem with this piece of code <?php $connect = mysqli_connect($host,$account,$password) OR DIE("Error !! Unable to connect to database"); $db = mysqli_select_db($connect,"$dbname") OR DIE( "Unable to select database "); $db="SELECT * FROM $tbleSearch WHERE fleet = $fnum"; if ($result = mysqli_query($connect,$db)) { if (mysqli_num_rows($result)) { while ($row = mysqli_fetch_assoc($result)){ ?> <table width="410" border="4" cellspacing="0" cellpadding="1"> <tr> <th>Type</th> <th>Fleet # </th> <th>Registration</th> <th>Body</th> <th>Chassis</th> </tr> <tr> <td><?php print "{$row['ltcode']}\n"; ?></td> <td><?php print "{$row['fleet']}\n"; ?></td> <td><?php print "{$row['rego']}\n"; ?></td> <td><?php print "{$row['body']}\n"; ?></td> <td><?php print "{$row['chassis']}\n"; ?></td> </tr> The problem is I search for number in a field called fleet, the result comes back and by other sections of the result I can confirm I have the correct record. But for some reason the print to screen fails to print out the fleet number what so ever. I have also tried printing out the String $flet which holds the number with the same result. This makes no sense what-so-ever to me so someone tell me the Gotcha, there must be one Thanks Roy.. Quote Link to comment Share on other sites More sharing options...
Orio Posted November 29, 2007 Share Posted November 29, 2007 Why double post? http://www.phpfreaks.com/forums/index.php/topic,169785.0.html Orio. Quote Link to comment Share on other sites More sharing options...
trq Posted November 29, 2007 Share Posted November 29, 2007 Firstly, your code only need be.... <td><?php print $row['ltcode']."\n"; ?></td> <td><?php print $row['fleet']."\n"; ?></td> <td><?php print $row['rego']."\n"; ?></td> <td><?php print $row['body']."\n"; ?></td> <td><?php print $row['chassis']."\n"; ?></td> next, for debugging puposes can you try this. <?php while ($row = mysqli_fetch_assoc($result)) { echo "<pre>"; print_r($row); echo "</pre>"; die(); } ?> What does that output? Quote Link to comment Share on other sites More sharing options...
janim Posted November 29, 2007 Share Posted November 29, 2007 you have tooooooooo much errors here $db = mysqli_select_db($connect,"$dbname") OR DIE( "Unable to select database "); $db="SELECT * FROM $tbleSearch WHERE fleet = $fnum"; why u use $db twice ? what is this table ? every thing is wrong here ! :-\ Quote Link to comment Share on other sites More sharing options...
Topshed Posted November 29, 2007 Author Share Posted November 29, 2007 Wow ... First the double post was due to a memory crash that reboot my machine, when I rebooted I did not realise the thing had posted when it crashed Sorry about that.. Next The person who answered on the other post solved my problem, but I could not thank him because the post has been deleted but he did say I was looping thru a whole table to print one record and there was a better way, unfortunatly lost with the deletion... Next Thank you Thorpe , for the shortened version of print, I am painfully learning from a Dummies book so I used the example exactly as it was printed.. Much the same as my sql statement pointed out by Janim is copied from my book, if anyone would be prepared to redo those lines that would be great. Thank you all for your help Regards Roy... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.