rajaahsan Posted May 11, 2011 Share Posted May 11, 2011 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 https://forums.phpfreaks.com/topic/236081-data-base-search/ Share on other sites More sharing options...
harristweed Posted May 11, 2011 Share Posted May 11, 2011 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 https://forums.phpfreaks.com/topic/236081-data-base-search/#findComment-1213644 Share on other sites More sharing options...
gizmola Posted May 11, 2011 Share Posted May 11, 2011 -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 https://forums.phpfreaks.com/topic/236081-data-base-search/#findComment-1213645 Share on other sites More sharing options...
rajaahsan Posted May 11, 2011 Author Share Posted May 11, 2011 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 https://forums.phpfreaks.com/topic/236081-data-base-search/#findComment-1213648 Share on other sites More sharing options...
gizmola Posted May 11, 2011 Share Posted May 11, 2011 rajaahsan, If you make another post without using the code tags I'm going to lock this thread, and might ban you as well. No more warnings. Link to comment https://forums.phpfreaks.com/topic/236081-data-base-search/#findComment-1213652 Share on other sites More sharing options...
rajaahsan Posted May 11, 2011 Author Share Posted May 11, 2011 gizmola soory i didnt understand please guide me i have writen code also :'( thank you Link to comment https://forums.phpfreaks.com/topic/236081-data-base-search/#findComment-1213658 Share on other sites More sharing options...
gizmola Posted May 11, 2011 Share Posted May 11, 2011 [code=php:0] Paste your code here [/code] Link to comment https://forums.phpfreaks.com/topic/236081-data-base-search/#findComment-1213660 Share on other sites More sharing options...
gizmola Posted May 11, 2011 Share Posted May 11, 2011 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 https://forums.phpfreaks.com/topic/236081-data-base-search/#findComment-1213662 Share on other sites More sharing options...
rajaahsan Posted May 11, 2011 Author Share Posted May 11, 2011 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 https://forums.phpfreaks.com/topic/236081-data-base-search/#findComment-1213682 Share on other sites More sharing options...
gizmola Posted May 11, 2011 Share Posted May 11, 2011 Strike 3 on posting code without tags. Link to comment https://forums.phpfreaks.com/topic/236081-data-base-search/#findComment-1213685 Share on other sites More sharing options...
Recommended Posts