User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 455,988 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,790 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 970 | Replies: 3
Reply
Join Date: Nov 2007
Posts: 183
Reputation: lydia21 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
lydia21 lydia21 is offline Offline
Junior Poster

select query

  #1  
Dec 6th, 2007
hi i have a form where the user will enter the data based on the user input i want to retrieve data

ex
1st textbox one get the standard (class of the student)
2nd & 3rd textbox get the range (ex rank 1 to 10)
when the user clicks submit...i want to display all the student name ,rank,class

table
id(primary key)
name

table
id
rank
........


i want to know how to fetch datas from database based on the three condition..which is dynamic
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: select query

  #2  
Dec 6th, 2007
Originally Posted by lydia21 View Post
hi i have a form where the user will enter the data based on the user input i want to retrieve data

ex
1st textbox one get the standard (class of the student)
2nd & 3rd textbox get the range (ex rank 1 to 10)
when the user clicks submit...i want to display all the student name ,rank,class

table
id(primary key)
name

table
id
rank
........


i want to know how to fetch datas from database based on the three condition..which is dynamic


What language do you intend to use for the script? That will determine to some extent how we can help you. Also show us what you have tried so far. Can you perform a successful SELECT with the MySQL client in a shell? If so, then all you need to do is modify that to suit your 'variable' input.

As well, this situation sets up a possible SQL Injection attack. If you don't know what that is look it up. If you are doing this through a web site you should definitely protect your data against an injection attack.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Join Date: Nov 2007
Posts: 183
Reputation: lydia21 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 5
lydia21 lydia21 is offline Offline
Junior Poster

Re: select query

  #3  
Dec 7th, 2007
html page
<form method="get" action="sort2.php">
<table>
<tr>
<td>SPid</td><td><input type="text" name="spid"></td>
</tr>
<tr>
<td>From</td><td><input type="text" name="from"></td>
<td>To</td><td><input type="text" name="to"></td>
<td><input type="submit" name="submit" value="submit"></td></tr>
</table>
</form>


sort2.php

<?php
$spid=$_REQUEST['spid'];
$to=$_REQUEST['to'];
$from=$_REQUEST['from'];
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");

$query="(select name,id from member where id=(select day,time from attend where day between '$from' and '$to')";




$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
echo "<table width='90%'>";

echo "<tr><td bgcolor='#008080'><font face='Times New Roman' color='#FFFFFF' size='2'><strong>Day</strong></font> </td>
<td bgcolor='#008080'><font face='Times New Roman' color='#FFFFFF' size='2'><strong>Name</strong></font> </td>
<td bgcolor='#008080'><font face='Times New Roman' color='#FFFFFF' size='2'><strong>Time</strong></font> </td></tr>";
if (mysql_num_rows($result) > 0 )
{

while($row = mysql_fetch_row($result))
{


echo "<tr>";

echo "<td>".$row[0]."</td><td>".$row[1]."</td><td> ".$row[2]."</td>";
echo "</tr>";
echo "<tr><td bgcolor='#008080'></td><td bgcolor='#008080'></td><td bgcolor='#008080'></td></tr>";
}
echo "</table>";
}



mytable

tb1
id(primary key)
name....

tb2

day,time,id........


please tell me how to fetch the name,day,time from the display it to the admin
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation: trudge is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: select query

  #4  
Dec 7th, 2007
Originally Posted by lydia21 View Post

$query="(select name,id from member where id=(select day,time from attend where day between '$from' and '$to')";


$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
echo "<table width='90%'>";

echo "<tr><td bgcolor='#008080'><font face='Times New Roman' color='#FFFFFF' size='2'><strong>Day</strong></font> </td>
<td bgcolor='#008080'><font face='Times New Roman' color='#FFFFFF' size='2'><strong>Name</strong></font> </td>
<td bgcolor='#008080'><font face='Times New Roman' color='#FFFFFF' size='2'><strong>Time</strong></font> </td></tr>";
if (mysql_num_rows($result) > 0 )
{

while($row = mysql_fetch_row($result))
{


echo "<tr>";

echo "<td>".$row[0]."</td><td>".$row[1]."</td><td> ".$row[2]."</td>";
echo "</tr>";
echo "<tr><td bgcolor='#008080'></td><td bgcolor='#008080'></td><td bgcolor='#008080'></td></tr>";
}
echo "</table>";
}



And what does this code display? From the look of it (not being a PHP programmer) it should give you what you want. You need to tell us why this doesn't 'work': does it display anything? Is it the wrong result set? What?

About the SQL injection: ask in a PHP forum or do a search on place holders in an SQL query.

PS You don't need to include all your HTML code - just the relevant code to deal with the problem.
Last edited by trudge : Dec 7th, 2007 at 4:55 am.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 9:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC