Enjoy an ad free experience by logging in. Not a member yet?
Register .
07-07-2012, 07:08 PM
PM User |
#31
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
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"?
07-07-2012, 07:22 PM
PM User |
#32
Regular Coder
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
Sorry I had image link there I meant author.
07-07-2012, 07:41 PM
PM User |
#33
Regular Coder
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
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 ..
07-07-2012, 07:50 PM
PM User |
#34
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Your query still does not include the author, only the title and imagelink.
07-07-2012, 07:51 PM
PM User |
#35
Regular Coder
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
Ok sorry thats what i was saying i meant author...
07-07-2012, 07:54 PM
PM User |
#36
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
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.
07-07-2012, 08:02 PM
PM User |
#37
Regular Coder
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
But it only gets the first one.
07-07-2012, 08:06 PM
PM User |
#38
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
No, it fetches all of them. But if you use your variables outside of the loop it will only be the last result iterated.
07-07-2012, 08:11 PM
PM User |
#39
Regular Coder
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
So as I said how could i get an individual one?
07-07-2012, 08:25 PM
PM User |
#40
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
An individual what? Record? Seek it if you don't need to iterate them all.
07-07-2012, 08:29 PM
PM User |
#41
Regular Coder
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
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.
07-07-2012, 08:33 PM
PM User |
#42
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
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.
07-07-2012, 08:33 PM
PM User |
#43
Regular Coder
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
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);
?>
07-07-2012, 08:36 PM
PM User |
#44
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
And a copy and paste of the code I added result in. . .?
07-07-2012, 08:48 PM
PM User |
#45
Regular Coder
Join Date: May 2011
Posts: 357
Thanks: 23
Thanked 1 Time in 1 Post
Would i do $li = mysql_data_seek($result, 4);
$record = mysql_fetch_assoc($result); ??
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 02:26 PM .
Advertisement
Log in to turn off these ads.