Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2005, 05:20 AM
Authorized User
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to elania
Default 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
__________________
i\'m am total newbie
 
Old February 20th, 2005, 12:23 PM
Authorized User
 
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old February 21st, 2005, 11:57 AM
Authorized User
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to elania
Default

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

i'm am total newbie
 
Old February 21st, 2005, 03:07 PM
Authorized User
 
Join Date: Jan 2005
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Decode function to display result in same row yogeshyl SQL Language 0 July 2nd, 2008 12:40 AM
Display Search Engine result in table using JSP sbc789 JSP Basics 3 December 3rd, 2007 11:35 PM
GridView and SQL More than one result = one result DarkForce ASP.NET 2.0 Basics 0 July 20th, 2007 04:29 AM
How to display the result in sqlpus editor lily611 Oracle 3 November 22nd, 2006 03:26 PM
display the result of query in textbox. Abhinav_jain_mca ADO.NET 4 August 3rd, 2004 03:34 AM





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