Page 1 of 1
How - SELECT all data in a column WHERE...
Posted: Mon Jul 30, 2012 9:30 pm
by Ghoz
Hi,
How to SELECT all data in U_Id from pryd table WHERE Pr_Id=185?
Please write in a proper code as I'm still new in php. Please help. Thanks!
U_Id Pr_Id
32 185
33 185
84 185
32 100
Re: How - SELECT all data in a column WHERE...
Posted: Mon Jul 30, 2012 9:58 pm
by requinix
Ghoz wrote:SELECT all data in U_Id from pryd table WHERE Pr_Id=185?
That is pretty damn close.
Re: How - SELECT all data in a column WHERE...
Posted: Mon Jul 30, 2012 10:30 pm
by mixa2000
Try this:
Code: Select all
<?php
// Connects to your Database
$host = ""; // Your host address for example if this is your localhost it will be localhost
$name = ""; // Name of your username that you connect with to your mysql server
$pass = ""; // Password that you use with that name
$db_name = ""; // The name of the database which this table is found at
mysql_connect("$host", "$name", "$pass") or die(mysql_error());
mysql_select_db("$db_name") or die(mysql_error());
$check = mysql_query("SELECT U_Id FROM pryd WHERE Pr_Id = '185'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
$U_Id = $info['U_Id'];
$Pr_Id = $info['Pr_Id'];
print "$U_Id, ";
}
?>
Hope this is helpful!

Please reply.
Re: How - SELECT all data in a column WHERE...
Posted: Mon Jul 30, 2012 11:27 pm
by mixa2000
One question, in the example you gave did you need the results to be; 32,33, and 84?
Re: How - SELECT all data in a column WHERE...
Posted: Tue Jul 31, 2012 1:24 am
by Ghoz
Yes. Going to try your suggestion. Thanks!
Re: How - SELECT all data in a column WHERE...
Posted: Tue Jul 31, 2012 3:40 am
by Ghoz
Thanks, it works!
Now how to insert the link to each result?
The link is something like below where uid result is taken from $U_Id
http://try000.com/index.php?section=profile&uid=29
Thanks!
Re: How - SELECT all data in a column WHERE...
Posted: Wed Aug 01, 2012 3:10 am
by mixa2000
You might want to try this, but if there is going to be more than one U_Id, then I am not really sure how that will work, ask any questions if this doesn't work, please reply.
Add this to the end of that script...
Code: Select all
<div align="center"><a href="index.php?section=profile&uid="
<?php
mysql_connect("$host", "$name", "$pass") or die(mysql_error());
mysql_select_db("$db_name") or die(mysql_error());
$check = mysql_query("SELECT U_Id FROM pryd WHERE Pr_Id = '185'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
$U_Id = $info['U_Id'];
print "$U_Id, ";
} ?>
"><b>Here</b></a></div>
Re: How - SELECT all data in a column WHERE...
Posted: Thu Aug 02, 2012 2:22 am
by Ghoz
Hi,
It can't display more than 1 result. I knew how to do it if only 1 result.
How to display more than 1 result with each link?
Thanks!
Re: How - SELECT all data in a column WHERE...
Posted: Sat Aug 04, 2012 9:18 pm
by mixa2000
Can you explain me what it should show when you click on the link?
Re: How - SELECT all data in a column WHERE...
Posted: Tue Aug 07, 2012 6:47 pm
by Pazuzu156
Here is a simple way of dong it, but overall I suggest doing this in an object oriented way.
Code: Select all
<?php
$c = mysql_query("SELECT `U_Id` FROM `pryd`");
while($r = mysql_fetch_array($c)) {
echo "<a href=\"http://try000.com/index.php?section=profile&uid=" . $r['U_Id'] . "\">http://try000.com/index.php?section=profile&uid=" . $r['U_Id'] . "</a><br>\n";
}
?>
Simple, but that should show all links with all the dynamic UIDs you're fetching from the database. Again, I'd do this in an OOP way for security and simplicity.
Re: How - SELECT all data in a column WHERE...
Posted: Mon Aug 27, 2012 10:06 am
by Ghoz
Hi Pazuzu, you didn't directly give me the solution but your suggestion did gave me an idea of how to do it. Actually I was stucked with <a href....Somehow I can't print/echo <a href... I suppose because of the '<' symbol.
Thanks!!
Re: How - SELECT all data in a column WHERE...
Posted: Mon Aug 27, 2012 12:23 pm
by Pazuzu156
You should be able to echo it out. Why you can't that's a bit odd. However, if you want to display the anchor tag to the world, replace < with <