Forum Moderators: coopster

Message Too Old, No Replies

Selecting certain row in MYSQL

Select rows.

         

jaslowry

12:11 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



I'm having trouble with this script. I need to select multiple rows(ie, the where won't work in this situation).

In MYSQL I have the members information. From there I need to pull datat from column 1, 2, 3, 5, and 8. I'm having a hard time doing this. Can anyone help?

Thanks.

Habtom

12:17 pm on Jul 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you want to pull out rows 1, 2, 3, 5, and 8 from a table? Does that table have a primary key? Can you post part of your code or anything which might help clear up the issue?

Habtom

jaslowry

12:18 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



Yes, it does have a specific key. It has a customid column(IE the 1, 2, etc.)

Habtom

12:22 pm on Jul 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Am I completly lost or this is what you are looking for:

SELECT * FROM thistable WHERE columnid=1 OR columnid=2 OR columnid=3 OR columnid=5 OR columnid=8

Hab

jaslowry

12:34 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



That works, however, is there a way to select it through the While query?

IE

<?while($row = mysql_fetch_array($sql)){?>
name:<?=$row{value}[2]?>
email:<?=$row{value}[4]?>
<?}?>

Or is that not possible? Sorry kinda new to this.

Habtom

12:48 pm on Jul 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?while($row = mysql_fetch_array($sql)){?>
name:<?=$row{value}[2]?>
email:<?=$row{value}[4]?>
<?}?>

If you wanted to display all how about just using the field names, like this:

<?php
while($row = mysql_fetch_array($sql)){
echo "name: ".$row['fieldname'];
echo "email: ".$row['fieldemail'];
}

... and welcome to Webmasterworld.

Habtom

[edit] Removed many of the PHP tags

[edited by: Habtom at 12:51 pm (utc) on July 10, 2007]

jaslowry

12:56 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



Thanks, however it is setup like this:

userid customid value

100 1 John
100 2 Doe
100 3 jdoe@example.com
100 5 1000 Wedge Field
100 6 Orlando
100 7 Fl
100 8 32887

[edited by: eelixduppy at 1:31 pm (utc) on July 10, 2007]
[edit reason] use example.com, please [/edit]

Habtom

1:02 pm on Jul 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then this should do it:

<?php
while($row = mysql_fetch_array($sql)){
echo "name: ".$row['value'][0];
echo "email: ".$row['value'];
}
?>

Unless you have a very good reason, there is no need of setting a table structure that way. It will be hard to maintain it and is not properly normalized.

[1][edited by: Habtom at 1:22 pm (utc) on July 10, 2007]

jaslowry

1:19 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



I totally agree. It was setup by a previous members area. When I use that it gives the following:

name: oemail: nname: aemail: sname: 2email: 0name: aemail: sname: iemail: nname: Lemail: name: 2email: 7

Is there something that I'm doing wrong in the query?

$sql = mysql_query("SELECT * FROM `user_customuserfields` WHERE userid = '$uid' ORDER BY customid");

jaslowry

4:13 pm on Jul 10, 2007 (gmt 0)

10+ Year Member



Does anyone know how/why this is showing like this? I can't find anything online.

Habtom

5:02 am on Jul 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See what kind of result the following gives you and proceed accessing the values that way.

When you reply, please post the result of this as well.

<?php
while($row = mysql_fetch_array($sql)){
print_r($row[value]);
}
?>

jaslowry

7:00 am on Jul 11, 2007 (gmt 0)

10+ Year Member



Thanks. When I use that it simply gives me all of the users information:
Jon Doe 124 Happy Place jdoe@example.com Orlando Fl 32789

Habtom

9:02 am on Jul 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The result is an array, the values you need can be retrieved by adding the array position as [0], [1] . . . .

just a tip

Hab

jaslowry

12:07 pm on Jul 11, 2007 (gmt 0)

10+ Year Member



When I add athe [0], [1] key all it does is cut the data:
IE: Jon Doe it outputs J D