Jump to content

Data Base search


rajaahsan

Recommended Posts

i have php code,

 

<?php

 

include ("connect.php");

$selecteddate = $_POST['sdate'];

$sql1 = "select date from game1";

$query1 = mysql_query($sql1) or die(mysql_error());

while($row = mysql_fetch_assoc($query1))

{

$rowdate = $row['date'];

// problem here i this while loop only compare my latest last value in

database. i want a code here which search all the data in "date" field.

}

if($selecteddate == $rowdate)

{

echo "Date already Exists";

}

 

else

{

// form insertion data code here which i have and working fine

}

SHINSTAR is online now Add to SHINSTAR's Reputation Report Post  Edit/Delete Message

Link to comment
Share on other sites

you have a brace } in the wrong place! try:

  while($row = mysql_fetch_assoc($query1))
{
$rowdate = $row['date'];
if($selecteddate == $rowdate)
{
echo "Date already Exists";
}

else
{
// form insertion data code here which i have and working fine
}
}

Link to comment
Share on other sites

-Use php code tags around your code

 

My best guess at your question, is that you want to add a WHERE clause to your query.

 

Personally I would do:

 

SELECT count(*) as countof FROM game1 WHERE `date` = '{$_POST['sdate']}'

 

This query will always return a single row you can fetch, with a single column.  There may be issues depending on the format of $_POST['sdate'] matching what mysql needs, as well as an issue with the data type of the date column in the table, but you can read about that in the mysql manual.

 

 

Link to comment
Share on other sites

i have tryed this code before,

while($row = mysql_fetch_assoc($query1))

{

$rowdate = $row['date'];

if($selecteddate == $rowdate)

{

echo "Date already Exists";

}

 

else

{

// form insertion data code here which i have and working fine

}

}

 

 

but when i do this my else part repeats hole and then show all the else values again and again...only on one value echo "Date already Exists" that matches my date value else repets its code again again for all values and displays again and again.

Link to comment
Share on other sites

rajaahsan,

  I realize you are not a native english speaker, but this forum is an english language forum.  We can not communicate effectively if you can not explain your problems adequately in the english language, or if you are unable to read and understand what people are saying to you.  You might be better off trying a php forum where there are people who speak and write in your native language.

 

Your code is simple, and it does what it is suppossed to do.  The problem here is that nobody can tell from your code what the problem is, or what you are trying to do. 

Link to comment
Share on other sites

Your are right that i am not an english speaker but i can understand very well but the php is little newer to me so thats why it creat problem to explain any body  well let me explain my code ,

 

this i my insert.php file which takes simple values from user using form and form action is this php code....hope understand.

<?php

 

include ("connect.php");                      //connect database sucessfully

$selecteddate = $_POST['sdate'];              // date variable set which comes from my form

$sql1 = "select date from game1";           

$query1 = mysql_query($sql1) or die(mysql_error());

while($row = mysql_fetch_assoc($query1))      // this is while code which i think may work well for me but unfortunately not

{

$rowdate = $row['date'];

 

 

if($selecteddate == $rowdate)      // compare values previously saved date in database with my new one

{

echo "Date already Exists";

}

 

else

{

echo "Weldone there is no date";

}

}

?>

 

the problem is that which is minor , this code also work fine it displays my date values from database which i have already saved before ,this code displays again and again because of while loop ,what should i do with this code so that is just only search all the value from date field and display once not again and again...hope now you got my point....

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.