Do you know how to put code and receive $_GET['id'] ? Id is first column in table articlesOriginally Posted by toplisek
Do you know how to put code and receive $_GET['id'] ? Id is first column in table articlesOriginally Posted by toplisek
So... you want to get the value of $_GET['id'] and find the article that matches that?
Well... you need to use a mysql query.... try this:
...I think that'll work. The WHERE command is what you need.PHP Code:$var = "SELECT * FROM articles WHERE id='".$GET_['id']."'";
mysqlquery($var);
I might be slightly off on syntax... hope it helps, though.
I have put while sentence :
It gives me error:PHP Code:
// Make rows for records
while($rec=mysql_fetch_array($result))
{
echo "<tr>";
for($i=0;$i<count($rec);$i++)
{
if($rec[$i])
$query = "SELECT ID FROM articles where ID = '$rec[$i]' ";
$s = mysql_query($query);
echo(mysql_error($s));
$result = mysql_fetch_assoc($s);
$ID=$result['ID'];
//echo the article
//echo("<p>".$result['ID']."</p>");
echo '<td><a href="article.php?ID='.$ID.'"><B>'.$rec[$i].'</B></A></td>';
}
echo "</tr>";
}
echo "</table>";
}
Warning: mysql_error(): supplied resource is not a valid MySQL-Link resource in .../read_news.php on line 59
Line 59 is:
echo(mysql_error($s));
Do you know how is correct to get ID number in this while sentence? Need help
Hey, Twey, or someone else, is the syntax right on the $query, line?
Looks like he's trying to embed a variable in it... inside single quotes, but it's in double quotes overall. that might be the problem, but I'm not sure.
Ok... wait... nevermind. I figured it out.
Here's the deal...
You are using mysql_error... that's a function that is SUPPOSED to show an error. That's not really an error you're getting... but you're just displaying an error there.
Or... maybe you're testing with that.
I'm confused.
Originally Posted by toplisek
I do not know how to get Id form each row of news.
Not at all. Nothing more than what usually happens when you forget to escape a quote.Originally Posted by djr33
Yes, that bit's fine; the single quotes are just part of the double-quoted string, and have no special meaning. However, there may be other problems... ID is presumably a number, which means it doesn't need to be quoted. You might as well select *, being as you'll want it later, and there's no performance decrease.Hey, Twey, or someone else, is the syntax right on the $query, line?
Looks like he's trying to embed a variable in it... inside single quotes, but it's in double quotes overall. that might be the problem, but I'm not sure.More importantly, I just noticed the layout of the code. If we add in the effective braces:PHP Code:$query = 'SELECT * FROM articles where ID = ' . $rec[$i] . ';';
So, if !$rec[$i], you're trying to execute a non-existant query. The fix is to move that brace to where it ought to be, or, better, to use the continue keyword to skip the rest of that iteration:PHP Code:// Make rows for records
while($rec=mysql_fetch_array($result))
{
echo "<tr>";
for($i=0;$i<count($rec);$i++)
{
if($rec[$i])
{
$query = "SELECT ID FROM articles where ID = '$rec[$i]' ";
}
$s = mysql_query($query);
echo(mysql_error($s));
$result = mysql_fetch_assoc($s);
$ID=$result['ID'];
//echo the article
//echo("<p>".$result['ID']."</p>");
echo '<td><a href="article.php?ID='.$ID.'"><B>'.$rec[$i].'</B></A></td>';
}
echo "</tr>";
}
echo "</table>";
}
This is the sort of problem that can be avoided by using a consistent and accurate indentation scheme.PHP Code:// Make rows for records
while($rec=mysql_fetch_array($result))
{
echo "<tr>";
for($i=0;$i<count($rec);$i++)
{
if(!$rec[$i]) continue;
$query = "SELECT ID FROM articles where ID = '$rec[$i]' ";
$s = mysql_query($query);
echo(mysql_error($s));
$result = mysql_fetch_assoc($s);
$ID=$result['ID'];
echo '<td><a href="article.php?ID='.$ID.'"><B>'.$rec[$i].'</B></A></td>';
}
echo "</tr>";
}
echo "</table>";
}
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
It gives me error with your above code:
Warning: mysql_error(): supplied resource is not a valid MySQL-Link resource in .../read_news.php on line 56
Line 56: echo(mysql_error($s));
and it shows only first row. I need to showw all rows which are on server from ID1 to last ID)
You do realize you're telling it to tell you an error, right?
You're using it for error checking purposes, yes?
All that's gonna do is tell you the last mysql error, so it would be anything in the entire page that resulted as an error... doesn't have anything to do with line56 except that's when you decided to display it.
I'm not saying you're wrong though... just wanted to be sure that is what you wanted.
-------
It would only show the first row. What Twey posted says 'select ID from...', meaning you're only gonna get data from the ID column.
It ought to show 0: Success, though.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Hmm... Yeah.
But if there were an error before that point, it would show that, right?
So it doesn't realy prove what the error is from?
Maybe you should be sure the error is right there by doing an error check like that after the last command, but before this one.
Also, use the command die('erroritshouldsay')... that way, when/if the funciton doesn't work, it'll stop working and display your error message, making it quite clear that's exactly where it didn't work.
PHP Code:mysql_query('something') or die('error doing something');
Bookmarks