•
•
•
•
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
![]() |
•
•
Join Date: Nov 2007
Posts: 183
Reputation:
Rep Power: 2
Solved Threads: 5
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
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
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation:
Rep Power: 2
Solved Threads: 20
•
•
•
•
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!"
"Others make web sites. We make web sites work!"
•
•
Join Date: Nov 2007
Posts: 183
Reputation:
Rep Power: 2
Solved Threads: 5
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
<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
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 176
Reputation:
Rep Power: 2
Solved Threads: 20
•
•
•
•
$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!"
"Others make web sites. We make web sites work!"
![]() |
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- sql query problem with MS Access and C# (C#)
- database connection(select ,insert query) within javascript function (JSP)
- Select Query Problem in access (MS Access and FileMaker Pro)
- SELECT query only of jobids with tagids from all catids (MS SQL)
- Problems in QUERY (Visual Basic 4 / 5 / 6)
- member group query (MySQL)
- hav a problem with this query (MySQL)
Other Threads in the MySQL Forum
- Previous Thread: update / replace help
- Next Thread: Timezone Adjustments


Linear Mode