Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-07-2012, 07:08 PM   PM User | #31
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Uhh, what? You don't query for "author" anywhere here, so you cannot extract it. All you have to work with is title and imagelink, nothing more, nothing less. If you want author, you'll need to query for it.
And I wouldn't bother with list if you are already pulling from $row array.
So what are you planning to do with "author" and "imageink"?
Fou-Lu is offline   Reply With Quote
Old 07-07-2012, 07:22 PM   PM User | #32
sherlockturtle
Regular Coder

 
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
sherlockturtle can only hope to improve
Sorry I had image link there I meant author.
sherlockturtle is offline   Reply With Quote
Old 07-07-2012, 07:41 PM   PM User | #33
sherlockturtle
Regular Coder

 
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
sherlockturtle can only hope to improve
Code:
$sql = "SELECT title, author FROM posts1 ORDER BY id DESC LIMIT 6";
$result = mysql_query( $sql ) or die( mysql_error() );
while($row = mysql_fetch_assoc($result))
{

     $il = $row["author"];
     $title   = $row["title"];
}

mysql_close($con);

?>

Last edited by sherlockturtle; 07-07-2012 at 07:52 PM..
sherlockturtle is offline   Reply With Quote
Old 07-07-2012, 07:50 PM   PM User | #34
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Your query still does not include the author, only the title and imagelink.
Fou-Lu is offline   Reply With Quote
Old 07-07-2012, 07:51 PM   PM User | #35
sherlockturtle
Regular Coder

 
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
sherlockturtle can only hope to improve
Ok sorry thats what i was saying i meant author...
sherlockturtle is offline   Reply With Quote
Old 07-07-2012, 07:54 PM   PM User | #36
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
The code you've posted above will work as expected. Each iteration for $il and $title will have the corresponding author and title for the current record.
Fou-Lu is offline   Reply With Quote
Old 07-07-2012, 08:02 PM   PM User | #37
sherlockturtle
Regular Coder

 
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
sherlockturtle can only hope to improve
But it only gets the first one.
sherlockturtle is offline   Reply With Quote
Old 07-07-2012, 08:06 PM   PM User | #38
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
No, it fetches all of them. But if you use your variables outside of the loop it will only be the last result iterated.
Fou-Lu is offline   Reply With Quote
Old 07-07-2012, 08:11 PM   PM User | #39
sherlockturtle
Regular Coder

 
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
sherlockturtle can only hope to improve
So as I said how could i get an individual one?
sherlockturtle is offline   Reply With Quote
Old 07-07-2012, 08:25 PM   PM User | #40
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
An individual what? Record? Seek it if you don't need to iterate them all.
Fou-Lu is offline   Reply With Quote
Old 07-07-2012, 08:29 PM   PM User | #41
sherlockturtle
Regular Coder

 
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
sherlockturtle can only hope to improve
As i said originaly I want to get a specific collums row in this case author and then the fifth one but I DIDINT know how to IMPLEMENT it into my current code.
sherlockturtle is offline   Reply With Quote
Old 07-07-2012, 08:33 PM   PM User | #42
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
You're not making any sense here.
If you want the FIFTH record from a resultset, use mysql_data_seek to move the resultset pointer to the fifth row. Then call a fetch on the row to pull the record out. I demonstrated this a number of posts back.
Fou-Lu is offline   Reply With Quote
Old 07-07-2012, 08:33 PM   PM User | #43
sherlockturtle
Regular Coder

 
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
sherlockturtle can only hope to improve
But I said I did not know how to implement it into my code.
Code:
sql = "SELECT title, author FROM posts1 ORDER BY id DESC LIMIT 6";
$result = mysql_query( $sql ) or die( mysql_error() );
while($row = mysql_fetch_assoc($result))
{

     $il = $row["author"];
     $title   = $row["title"];
}

mysql_close($con);

?>
sherlockturtle is offline   Reply With Quote
Old 07-07-2012, 08:36 PM   PM User | #44
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
And a copy and paste of the code I added result in. . .?
Fou-Lu is offline   Reply With Quote
Old 07-07-2012, 08:48 PM   PM User | #45
sherlockturtle
Regular Coder

 
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
sherlockturtle can only hope to improve
Would i do $li = mysql_data_seek($result, 4);
$record = mysql_fetch_assoc($result); ??
sherlockturtle is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:26 PM.


Advertisement
Log in to turn off these ads.