4 Replies - 755 Views - Last Post: 21 December 2011 - 06:53 AM Rate Topic: -----

#1 PixelBit  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 233
  • Joined: 17-July 11

How to search for a name in a mysql database and store the values.....

Posted 21 December 2011 - 06:01 AM

How to search for a name in a mysql database and store the values that come after it in its row to separate variables, usually when i so this I use mysql_result but for that I need to know the row number, but here the row number is unknown. So how can i do this?
Is This A Good Question/Topic? 0
  • +

Replies To: How to search for a name in a mysql database and store the values.....

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3716
  • View blog
  • Posts: 5,976
  • Joined: 08-June 10

Re: How to search for a name in a mysql database and store the values.....

Posted 21 December 2011 - 06:22 AM

I'm not understanding what you mean. Could you elaborate?

Usually when you query MySQL using mysql_query, you do something like this:
$result = mysql_query("SELECT ...");

while ($row = mysql_fetch_assoc($result)) 
{
	echo $row["colname"];
}


Which allows you to loop through each row in the result set and use the data there. There is no need to know the actual row number in this scenario.
Was This Post Helpful? 0
  • +
  • -

#3 PixelBit  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 233
  • Joined: 17-July 11

Re: How to search for a name in a mysql database and store the values.....

Posted 21 December 2011 - 06:31 AM

View PostAtli, on 21 December 2011 - 06:22 AM, said:

I'm not understanding what you mean. Could you elaborate?

Usually when you query MySQL using mysql_query, you do something like this:
$result = mysql_query("SELECT ...");

while ($row = mysql_fetch_assoc($result)) 
{
	echo $row["colname"];
}


Which allows you to loop through each row in the result set and use the data there. There is no need to know the actual row number in this scenario.


Yeh i wasnt saying there was a need to, I was sayign thats how i usually did it and i didn't know a different way, I was asking for that different way.

I'll take a look at the code above, thanks.

I usually do somethign liek this:
$amount = mysql_result($result, $row, "amount");

This post has been edited by PixelBit: 21 December 2011 - 06:32 AM

Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3716
  • View blog
  • Posts: 5,976
  • Joined: 08-June 10

Re: How to search for a name in a mysql database and store the values.....

Posted 21 December 2011 - 06:50 AM

Ok, I see.

There is little difference between doing what I posted earlier and this:
for ($i = 0; $i < mysql_num_rows($result); ++$i)
{
	echo mysql_result($result, $i, "colname");
}


Except, as the manual warns: using mysql_result can be significantly slower for large sets. Personally I only ever use mysql_result to get scalar results; to fetch the one and only cell from a result set that returns only one value. And even then I am just as likely to use mysql_fetch_row.

Or I should rather say: I "was" just as likely to use it. I haven't actually used the old MySQL extension for anything real for ages. I upgraded to MySQLi and/or PDO a long time ago. (PDO, usually.) I highly recommend you do the same.
Was This Post Helpful? 2
  • +
  • -

#5 PixelBit  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 233
  • Joined: 17-July 11

Re: How to search for a name in a mysql database and store the values.....

Posted 21 December 2011 - 06:53 AM

View PostAtli, on 21 December 2011 - 06:50 AM, said:

Ok, I see.

There is little difference between doing what I posted earlier and this:
for ($i = 0; $i < mysql_num_rows($result); ++$i)
{
	echo mysql_result($result, $i, "colname");
}


Except, as the manual warns: using mysql_result can be significantly slower for large sets. Personally I only ever use mysql_result to get scalar results; to fetch the one and only cell from a result set that returns only one value. And even then I am just as likely to use mysql_fetch_row.

Or I should rather say: I "was" just as likely to use it. I haven't actually used the old MySQL extension for anything real for ages. I upgraded to MySQLi and/or PDO a long time ago. (PDO, usually.) I highly recommend you do the same.

hmm ok thanks :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1