Displaying from DB based on $articleid

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Displaying from DB based on $articleid

Post by 4Boredom »

This spits out Query was empty

Is there a more effective way then this to display title? Once I figure this out I can apply it to other vars....

submitted_articles, articleid, and title are all correct structure...

Code: Select all

$display= mysql_query("SELECT 'title' FROM 'submitted_articles' WHERE 'articleid'=1");
$result= mysql_query($display) or die ($ERROR_MSG . mysql_error());

echo'
<table width="100%">
<tr width="100%">

<td width="75%" valign="top">
<b>$title</b> - <i>Written by DeReK</i><hr>
blah
</td>....

the rest doesnt pertain
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You've asked MySQL to select the string "title" from the string "submitted_articles" where the string "articleid" is equal to one. I believe you intended those to be field and table references, therefore recommend you remove the single quotes.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Re: Displaying from DB based on $articleid

Post by tecktalkcm0391 »

Try...

Code: Select all

$display= mysql_query("SELECT `title` FROM `submitted_articles` WHERE `articleid`='1' ");
$result= mysql_query($display) or die ($ERROR_MSG . mysql_error());
$info = mysql_fetch_array($result);

echo "
<table width="100%">
<tr width="100%">

<td width="75%" valign="top">
<b>$info['title']</b> - <i>Written by DeReK</i><hr>
blah
</td>....

the rest doesnt pertain
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

still says Query Was Empty

I tried it removing the 's too
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

maybe the error is with articleid=1

thats all i can think of?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

$result=mysql_query($display) or die ('<div>' . mysql_error(). ': ' . $display . "</div>\n");
What does that print?

4Boredom wrote:still says Query Was Empty
meaning: you're not sending a query at all, like mysql_query(NULL); or mysql_query('');
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Displaying from DB based on $articleid

Post by onion2k »

tecktalkcm0391 wrote:

Code: Select all

$display= mysql_query("SELECT `title` FROM `submitted_articles` WHERE `articleid`='1' ");
$result= mysql_query($display) or die ($ERROR_MSG . mysql_error());
$display is the result of mysql_query(). Putting that into another mysql_query() isn't going to work.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Few questions to answer...

1) is there data in the table to select?
2) What is the field type for article?
3 What does

Code: Select all

SELECT `title` FROM `submitted_articles`;
return?
Post Reply