Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1555 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

PHP Results issue

Thread title: PHP Results issue
Closed Thread    
    Thread tools Search this thread Display Modes  
12-09-2008, 10:45 AM
#1
Kimb3r is offline Kimb3r
Status: I'm new around here
Join date: Apr 2008
Location:
Expertise:
Software:
 
Posts: 8
iTrader: 0 / 0%
 

Kimb3r is on a distinguished road

  Old  PHP Results issue

Im looking to make a members type page that when you click on the member name (coming from an SQL database) it will then go to their page where for now their name will appear. I have it all working except on their page it just outputs all the names from the database. Example: http://xyzmedia.co.uk/wow/test.php

Code:
Code:
<table width="100%" height="100%" border="0" cellpadding="5" cellspacing="0">
  <tr>
    <td width="44%" valign="top"><p>Name:</p>
        <? mysql_connect("localhost", "admin", "*******") or die(mysql_error());
mysql_select_db("members") or die(mysql_error());

$result = mysql_query("SELECT * FROM members order by name") or die (mysql_error());
while ($row = mysql_fetch_array($result)) 			

{
echo "<a href='?id=" . $row[name]	."'>" . $row[name]	."</a><br />";
}
?>
        <p><br />
          Add Your Name </p>
        <form action="addmember.php" method="post" name="addmember" id="addmember">
          <input type="text" id="name" name="name" value="" />
          <input name="submit" type="submit" value="Add" />
      </form></td>
    <td width="56%" valign="top"><? mysql_connect("localhost", "admin", "*******") or die(mysql_error());
mysql_select_db("members") or die(mysql_error());

$result = mysql_query("SELECT * FROM members order by name") or die (mysql_error());
while ($row = mysql_fetch_array($result)) 			

{
		echo "" . $row[name]	."";	
}
?>
    </td>
  </tr>
</table>

12-09-2008, 02:25 PM
#2
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

You would have to do something like this:
PHP Code:
if (isset($_GET['id'])) {
    
$result mysql_query("SELECT * FROM members WHERE name = '%s'"mysql_real_escape_string($_GET['id']));
    if (
mysql_num_rows($result) > 0) {
         
// use result to display member info
    
} else {
        
// error or no user in database
    
}
} else {
    
// list members

Something like that. Google for some articles on using query strings in your URL using the GET method, and using them to display the info you want.

12-10-2008, 01:07 PM
#3
Kimb3r is offline Kimb3r
Status: I'm new around here
Join date: Apr 2008
Location:
Expertise:
Software:
 
Posts: 8
iTrader: 0 / 0%
 

Kimb3r is on a distinguished road

  Old

Thanks for that, started playing around with what you wrote and am struggling to output data from the database. Thanks for the info on looking up query strings and the GET method. All I could find on GET was a form which the user inserts their name then I echo their name they type in the members bit which I wanted.

Only problem is I want it to be more personal where you can simply click on any members name instead of doing a search for each one. So only having a problem getting the names from the database now, any more pointers?

Thanks

12-11-2008, 03:45 PM
#4
Mitchell is offline Mitchell
Status: Junior Member
Join date: Oct 2007
Location: Sweden
Expertise:
Software:
 
Posts: 45
iTrader: 0 / 0%
 

Mitchell is on a distinguished road

Send a message via AIM to Mitchell Send a message via MSN to Mitchell

  Old

Just use a while loop and some queries.
PHP Code:
<?php
    $myquery 
mysql_query("SELECT * FROM `users`") or die(mysql_error());

    while(
$row mysql_fetch_array($myQuery)) {
        echo 
$row['myName']."\n";
    }
?>
Not sure that's what you ment.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed