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

Archived

This topic is now archived and is closed to further replies.

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