Jump to content

Stupid Odd Problem


Topshed

Recommended Posts

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..

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 ! :-\

Link to comment
Share on other sites

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...

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.