Jump to content

[SOLVED] mysql_fetch_array() problem


techkid

Recommended Posts

the file is blog.php

 

what the file do is blog.php list all the content generated

 

blog.php?act=view&id=6 <-- this one shows individual post

 

blog.php?act=view&id=6 is not working it says

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\supp\b-class.php on line 17

 

here is the code for it

//view the news article!
if(isset($_GET['act']) && $_GET['act'] == "view")
{
$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM content WHERE index = '$id'");
while($row = mysql_fetch_array($sql))
{
echo "<div id='post'>";
echo "<h3>" . $row['title'] . "</h3>";
echo '<a href="blog.php?act=view&id='.$row['index'].'">'.$row['title'].'</a>';
echo $row['news'];
echo '<p class="postend">Posted by: '.$row['author'].' | Date:'.$row['date'].'</p></div>';
}

Link to comment
Share on other sites

Change this

 

$sql = mysql_query("SELECT * FROM content WHERE index = '$id'");

 

to

 

$sql = mysql_query("SELECT * FROM content WHERE index = '$id'") or trigger_error(mysql_error());

 

and see if there is an error.  Are you sure that the field is index and not Index, or something like that?

 

Link to comment
Share on other sites

Now I've got 2 errors

 

Notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index = '6'' at line 1 in C:\wamp\www\techmv.net\b-class.php on line 16

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\techmv.net\b-class.php on line 17

 

Here is the database scheme:

2cdhfdt.jpg

Link to comment
Share on other sites

Add die(mysql_error()) so we can see the output. (See below code for addition)

 

//view the news article!
if(isset($_GET['act']) && $_GET['act'] == "view")
{
$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM content WHERE index = '$id'");
die(mysql_error());//ADDED HERE
while($row = mysql_fetch_array($sql))
{
echo "<div id='post'>";
echo "<h3>" . $row['title'] . "</h3>";
echo '<a href="blog.php?act=view&id='.$row['index'].'">'.$row['title'].'</a>';
echo $row['news'];
echo '<p class="postend">Posted by: '.$row['author'].' | Date:'.$row['date'].'</p></div>';
}

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.