Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 01-14-2010, 11:55 PM   #1
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
how do i echo all rows in php?

Is there a way to show all rows in a database table without having to echo row[0] echo row [1] for each field?



did select * from blah where id=1 but theres about 50 fields (keyword tags) so can i just echo them all?
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2010, 11:57 PM   #2
SmellyNose
Confirmed User
 
SmellyNose's Avatar
 
Industry Role:
Join Date: Aug 2009
Location: me at smellynose.com
Posts: 206
It depends what you're using to get your data.

You could do
Code:
foreach($data as $v) {
    echo $v;
}
Or if you're using mysql_fetch_array (or _assoc) you could do:

Code:
$r = mysql_fetch_assoc($mysql_resource_link_doo_dar_thing);
while($r) {
    echo $r['tag']; // Use $r[index_of_Tag] if you are using _array
    $r = mysql_fetch_array($mysql_resource_link_doo_dar_thing);
}
I'm on ICQ if you need 594086663

Last edited by SmellyNose; 01-14-2010 at 11:59 PM..
SmellyNose is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-14-2010, 11:58 PM   #3
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
thx dude, ill give it a try
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2010, 12:02 AM   #4
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
hmm cant figure it out, heres my code:

Code:
$alltags = mysql_query("SELECT * FROM tags WHERE user_id=$id");


while($row1 = mysql_fetch_array($alltags))
  {
echo $row1['tag_cen']; //i want to echo fields here instead of just tag_cen

  }
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2010, 12:06 AM   #5
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
Code:
while($row = mysql_fetch_array($alltags)) 
{
   echo implode(', ',$row);
}
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2010, 12:07 AM   #6
SmellyNose
Confirmed User
 
SmellyNose's Avatar
 
Industry Role:
Join Date: Aug 2009
Location: me at smellynose.com
Posts: 206
Quote:
Originally Posted by mkx View Post
hmm cant figure it out, heres my code:

Code:
$alltags = mysql_query("SELECT * FROM tags WHERE user_id=$id");


while($row1 = mysql_fetch_array($alltags))
  {
echo $row1['tag_cen']; //i want to echo fields here instead of just tag_cen

  }
Add another echo in your while loop to see if it is actually going into it.

And add:
Code:
if($alltags === false) {
    die("Query failed");
}
uk3.php.net/mysql_fetch_array

And $id is definitely numeric isn't it?

Code:
$id = preg_replace('/[^0-9]/', '', $id);
Otherwise you could be open to mysql injection
SmellyNose is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2010, 12:17 AM   #7
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
that works good, thanks very much guys,

btw, is there anyway to skip the first field from echoing? since the first field is the id and i dont want to echo it. the 30 fields that follow are tags
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2010, 12:21 AM   #8
SmellyNose
Confirmed User
 
SmellyNose's Avatar
 
Industry Role:
Join Date: Aug 2009
Location: me at smellynose.com
Posts: 206
You could do it in MySQL, but I'd probably do it in the PHP as MySQL limits are usually what break things.

You could use an int to see where you are, like this:
Code:
$c=0;
while($row) {
if($c==0) { break;}
echo $row['tag'];
$c++;
}
SmellyNose is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2010, 12:29 AM   #9
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
thanks again
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2010, 12:35 AM   #10
SmellyNose
Confirmed User
 
SmellyNose's Avatar
 
Industry Role:
Join Date: Aug 2009
Location: me at smellynose.com
Posts: 206
No problem. Anybody looking for a web developer, ICQ Me: 594086663
SmellyNose is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2010, 03:09 AM   #11
Richard - Triplexcash
Confirmed User
 
Richard - Triplexcash's Avatar
 
Join Date: Aug 2003
Posts: 915
Quote:
Originally Posted by AdultStoriesNow View Post
No problem. Anybody looking for a web developer, ICQ Me: 594086663
Can you drop me an email please or hit me on my icq...can't seem to locate you with my IM client on ICQ.

Thanks.
__________________
Richard
[email protected]
ICQ: 322574184
Richard - Triplexcash is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.