How - SELECT all data in a column WHERE...
Moderator: General Moderators
How - SELECT all data in a column WHERE...
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
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...
That is pretty damn close.Ghoz wrote:SELECT all data in U_Id from pryd table WHERE Pr_Id=185?
Re: How - SELECT all data in a column WHERE...
Try this:
Hope this is helpful!
Please reply.
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, ";
}
?>
Re: How - SELECT all data in a column WHERE...
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...
Yes. Going to try your suggestion. Thanks!
Re: How - SELECT all data in a column WHERE...
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!
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...
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...
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...
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!
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...
Can you explain me what it should show when you click on the link?
Re: How - SELECT all data in a column WHERE...
Here is a simple way of dong it, but overall I suggest doing this in an object oriented way.
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.
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";
}
?>- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Re: How - SELECT all data in a column WHERE...
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!!
Thanks!!
Re: How - SELECT all data in a column WHERE...
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 <
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156