Be a Supporter!

not found in MySQL result?

  • 1,586 Views
  • 2 Replies
New Topic Respond to this Topic
bumcheekcity
bumcheekcity
  • Member since: Jan. 19, 2003
  • Offline.
Forum Stats
Member
Level 27
Blank Slate
not found in MySQL result? 2004-08-16 05:55:21 Reply

<?php
include 'dbconnect.php';
$query = "SELECT * FROM ads WHERE id > 0";
$result = mysql_query($query);
$num = mysql_num_rows($result);
$count = 0;

while ($count != $num)
{
$adname = mysql_result($result,$count,"AdvertName");
$adref = mysql_result($result,$count,"AdvertReference");
$adlink = mysql_result($result,$count,"AdvertLink");
$adid = mysql_result($result,$count,"UniqueId");
echo "<input type='checkbox' name='$adid' value='ON'> $adref $adname<br><br>";
echo "$count --- $num";
$count++;
}
?>

This just generates a HUGE page of errors telling me:

Warning: mysql_result(): AdvertName not found in MySQL result index 3 in /home/coors/public_html/admin/adshtmlrip.php on line 17

Warning: mysql_result(): AdvertReference not found in MySQL result index 3 in /home/coors/public_html/admin/adshtmlrip.php on line 18

Warning: mysql_result(): AdvertLink not found in MySQL result index 3 in /home/coors/public_html/admin/adshtmlrip.php on line 19

Warning: mysql_result(): UniqueId not found in MySQL result index 3 in /home/coors/public_html/admin/adshtmlrip.php on line 20

Then it prints a checkbox, then more errors, because of the while command. I haven't encountered this error before... Can anyone see where I'm going wrong?

PONGpaddle
PONGpaddle
  • Member since: Sep. 23, 2003
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to not found in MySQL result? 2004-08-16 08:22:41 Reply

Firstly, does the table or database exist yet, and have ou put anything in it?

Secondly, why is "WHERE id > 0" on the end of your query? Surely you'd want all the adverts to show up, or not have any id under 0?

CronoMan
CronoMan
  • Member since: Jul. 19, 2004
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to not found in MySQL result? 2004-08-17 04:42:34 Reply

:<?php
:include 'dbconnect.php';
:$query = "SELECT * FROM ads WHERE id > 0";
:$result = mysql_query($query);
:$num = mysql_num_rows($result);
:$count = 0;

:while ($count != $num)
:{
:$adname = mysql_result($result,$count,"AdvertName");
:$adref = mysql_result($result,$count,"AdvertReference");
:$adlink = mysql_result($result,$count,"AdvertLink");
:$adid = mysql_result($result,$count,"UniqueId");
:echo "<input type='checkbox' name='$adid' value='ON'> $adref $adname<br><br>";
:echo "$count --- $num";
:$count++;
:}
:?>

instead :

<?php
include "dbconnect.php";

$query = mysql_query("SELECT * FROM ads")
or die(mysql_error());

$num = mysql_num_rows($query);

for($i=0;$i<$num;$i++)
{
$record = mysql_fetch_object($query);

echo "<input type=checkbox name=$record->UniqueId value=on>$record->AdvertReference $record->AdvertName<br><br>";
echo "$i --- $num";
}

Your code made no sense.
If it says AdvertName not found, it's probably becuase you've mis-spelled avdertname. Remember the query is case-sensitive.
And why did you use a while loop instead of a for loop?


"no sound in ass"