Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

56 users online



Creating Simple Query Form

Creating Simple Query Form

Currently viewing this thread: 1 (0 members and 1 guests)


zigzag2001

zigzag2001

Status: Offline!

Creating Simple Query Form

am a beginner user of PHP and i was desiging a website that keeps exam results of my friends in University, I already have a Mysql database holding records with Id Numbers, Names, resuls, etc...,

and I want to create a search field to place in the site (.php page) that searches in one field only (ID Number) and then gives back the result that matches the Id number showing all field in the table with only one record that match the Id number Smile

ed-d

ed-d

Status: Offline!
PHP:

<?php
$query 
"SELECT column1, column2 FROM tablename WHERE id='$_POST[searchid]'";
$result mysql_query($query) or die(mysql_error());
$row mysql_fetch_assoc($result);
if (
$row)
{
     
//id was found ... do ...
}
else
{
     
//id was not found
}
?>

euphoria_dream

euphoria_dream

Status: Offline!

Well i had ths same problem with my site and thanks that was really helpful but here comes another problem:

What will i type instead of "//id was found ... do ..." and "//id was not found" to get what i want (read below)

In my site i used

PHP:

<?php

echo "<TR><TD>";
echo 
$row["IdNumber"];
echo 
"";
echo 
$row["Name"];
echo 
"<TD>";
echo 
$row["Year"];
echo 
"<TD>";
echo 
$row["Grade"];

?>

that worked from the sense that i got my results from my search on the page, but i didn't want them to look the way they did, i mean i got plan text results sticking together in a messy way so i thought about creating a table with headers of colums like "Id Number,Name, Year, Marks(or grades)" and in another row just below the headers i get my results in a good looking way. I am not at all good at PHP, and i don't have time to practice on it cuz i have to finish this site within 2 more weeks, so please help me, just the way of creating table and how can i insert the resukts into the wanted cells, and yah tell me if i can do most of the code (table creation) with HTML or not, cuz i am more familiar with it than php.

Last edited by euphoria_dream, June 4th, 2004 07:02 AM (Edited 1 times)

ed-d

ed-d

Status: Offline!

its just HTML broken up into echos tatements

PHP:

<?php
echo "<table width=\"100%\" border=\"1\">\n";
echo 
"<tr>\n";
echo 
"<td>ID Number</td>\n<td>Name</td>\n<td>Year</td><td>Grade</td>\n";
echo 
"</tr>\n";
echo 
"<tr>\n";
echo 
"<td>$row[IdNumber]</td><td>$row[Name]</td><td>$row[Year]</td><td>$row[Grade]</td>\n";
echo 
"</tr>\n</table>\n";
?>

euphoria_dream

euphoria_dream

Status: Offline!

well thanks i just frgot to include the

PHP:

<?php

echo "<table>"//up

//and

echo "</tr>\n</table>\n"//down
?>

Thanks again and hope "zigzag2001" got it too

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0077 seconds.