p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   PHP Databases (http://p2p.wrox.com/forumdisplay.php?f=97)
-   -   how to display the result (http://p2p.wrox.com/showthread.php?t=25803)

elania February 20th, 2005 05:20 AM

how to display the result
 
i'm doing VIEW function. and this is my Mysql statement:

$sql = "SELECT * FROM staff, student WHERE f_Username.staff LIKE '$user' OR t_Username.student LIKE '$user'";
$result = mysql_query($sql, $conn);

the result can be from table staff or student. now how am i suppose to display the result?

i'm am total newbie

Gotaka4 February 20th, 2005 12:23 PM

i think you got your query the other way around. It should be like:

$sql = "SELECT * FROM staff, student WHERE staff.f_Username LIKE '%$user%' OR student.t_Username LIKE '%$user%'";
$result = mysql_query($sql) or die (mysql_error());

while ($row = mysql_fetch_assoc($result)){
    //Here you can print your data however you like.
    //$row is an array that contains all of your results and you can
    //display them like the following.
    echo $row['f_Username'];
}

----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq

elania February 21st, 2005 11:57 AM

echo $row['f_Username']; -- will this display result from table student?

i'm am total newbie

Gotaka4 February 21st, 2005 03:07 PM

if the fieldname is not unique between the two tables, you might have some problems. So to obviate this problem, either use the numerical index of the array or do this as your select statement.:

$sql = "SELECT f_Username as username, t_Username as staff_username FROM staff, student WHERE staff.staff_username LIKE '%$user%' OR student.username LIKE '%$user%'";


----------------
Never bother to learn something not knowing which does not do you any harm, and never neglect to learn something whose negligence will increase your ignorance - Imam Jafar Sadeq


All times are GMT -4. The time now is 09:14 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.