GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   how do i echo all rows in php? (https://gfy.com/showthread.php?t=948467)

mkx 01-14-2010 11:55 PM

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?

SmellyNose 01-14-2010 11:57 PM

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

mkx 01-14-2010 11:58 PM

thx dude, ill give it a try

mkx 01-15-2010 12:02 AM

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

  }


Brujah 01-15-2010 12:06 AM

Code:

while($row = mysql_fetch_array($alltags))
{
  echo implode(', ',$row);
}


SmellyNose 01-15-2010 12:07 AM

Quote:

Originally Posted by mkx (Post 16748314)
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

mkx 01-15-2010 12:17 AM

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

SmellyNose 01-15-2010 12:21 AM

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++;
}


mkx 01-15-2010 12:29 AM

thanks again

SmellyNose 01-15-2010 12:35 AM

No problem. Anybody looking for a web developer, ICQ Me: 594086663 :)

Richard - Triplexcash 01-15-2010 03:09 AM

Quote:

Originally Posted by AdultStoriesNow (Post 16748377)
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.


All times are GMT -7. The time now is 02:52 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc