标签云

微信群

扫码加入我们

WeChat QR Code

I tried to read out data from a specific date from a MySQL database.What I wanted is for PHP to get all of the data from the database within a specific date that I entered, but it seems that the script just got only the first row of data and left out the rest.Can you please help me with code to achieve this.<?phpif(isset($_REQUEST['query'])){$searchQuery = $_POST['data-search'];//connceting to db$con = mysql_connect($_SERVER['SERVER_NAME'],'root','');if(!$con){die("Error connecting: ".mysql_error());exit;}//selecting db$dbSelect = mysql_select_db("directory",$con);$query = "SELECT * FROM websites WHERE Date LIKE '$searchQuery'";//executing query$result = mysql_query($query,$con);if(!$result){die("Could not connect: ".mysql_error());}while($row = mysql_fetch_array($result)){$searchOutput = "<html><body><table border=1><tr><td>Website Title</td><td>Website URL</td><td>About Website Content</td></tr><tr><td>".$row['Title']."</td><td>".$row['URL']."</td><td>".$row['Content']."</td></tr></table>";}$searchSuccess = "<p>Your Search was successful</p</body></html>";mysql_close($con);echo $searchOutput;echo $searchSuccess;}else{echo "Invalid";}?>


You realise that your $searchOutput string is being overwritten for every row you've retrieved. Please also make an effort to learn html markup for tables, rows and cells.... the markup itself is completely inconsistent

2019年04月18日34分27秒

And you're starting a new HTML document/body per each row, which is not real valid HTML and might turn out to be rendered bogus from browser to browser.

2019年04月18日34分27秒

how do i solve the problem.

2019年04月18日34分27秒

Thank you this work out.

2019年04月19日34分27秒