Jump to content

[SOLVED] while loop of $row = mysql_fetch_assoc($result) not working


Poddy

Recommended Posts

i have the following code:

if ($bd == null) {
$sql = "select * from `data` where `name` LIKE '$name' AND `spot` LIKE '$line' AND `piret` LIKE '$piret' ";
$result = mysql_query($sql) or die ('blah balh' . mysql_error());
$numrows = mysql_num_rows($result);

while ($row = mysql_fetch_assoc($result)) {

$timestamp = $row['timestamp'];
$line = $row['spot'];
$piret = $row['piret'];
$name = $row['name'];
$comment = $row['text'];

/*
$takeoff = $row['takeoff'];
$cockpit = $row['cockpit'];
$appear = $row['appear'];
$take += $takeoff;
$cock += $cockpit;
$appe += $appear;
*/

echo "
<table width='200' border='1'>
  <tr>
    <td> $timestamp </td>
    <td> $name </td>
  </tr>
  <tr>
    <td rowspan='2'> $comment </td>
    <td> פירט: $piret </td>
  </tr>
  <tr>
    <td> ליין: $line </td>
  </tr>";
  
$sql = "select `short` from `questions`";
$result = mysql_query($sql) or die ('error' . mysql_error());
while ($row = mysql_fetch_assoc($result)) {
$short = $row['short'];
qvalues($short);
}  

echo "
</table>
";
}

}

 

function code:

function qvalues ($var) {

$sql = "SELECT * FROM `data` where `$var` LIKE '%'";
$result = mysql_query($sql) or die ('error' . mysql_error());
$row = mysql_fetch_assoc($result);
$points = $row["$var"];

$sql = "select `text` FROM `questions` where `short`='$var'";
$result = mysql_query($sql) or die ('error' . mysql_error());
$row = mysql_fetch_assoc($result);

$text = $row['text'];



echo "<tr><td> $points </td> <td> $text </td></tr>";
}

 

this code generates a table with a name, timestamp, comment, piret and spot aswell as the score points

this worked fine until now, but i needed to be able to add dynamically questions to the database

so the table needed to be a bit more dynamic as well, i created the function to retrieve the data i need... it works

however as of the change for the function the while($row = mysql_fetch_assoc($result))

only shows me 1 table, aka giving the script only 1 row...

 

any help is appreciated

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.