Solved

php query

Posted on 2016-07-30
6
27 Views
Last Modified: 2016-07-30
$sql = "SELECT id, file_name FROM files";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
	// output data of each row
	echo '<table width="" align="center">';
	$i = 0;
	while ($row = $result->fetch_assoc()) {
		if (0 === ($i % 4)) {
			echo '<tr valign="top">';
		}
		echo "<td class='tableclass'>ID: " . $row["id"] . "   Name: " . $row["file_name"] . "</td>";
		echo "<td class='imagefont smooth'>&nbsp;   Image: <a href='" . $largeimage . $row["id"] . "'><img src=" . $image . $row["file_name"] . " width='50px' height='50px' /></a><a href='" . $deleteimage . $row["id"] . "'>$link Delete Image from database</a>$linkend&nbsp;</td>";
		if (3 === ($i % 4)) {
			echo "</tr>";
		}
		$i++;
	}
} else {
	echo "Current Images in Database:";
}
$conn->close();
echo '</table>';

?>

</br>

<?php
$sql2 = "SELECT id, f_name FROM documents";
$result2 = $conn->query($sql2);

if ($result2->num_rows > 0) {
	// output data of each row
	echo '<table width="" align="center">';
	$i = 0;
	while ($row = $result2->fetch_assoc()) {
		if (0 === ($i % 4)) {
			echo '<tr valign="top">';
		}
		echo "<td class='tableclass'>ID: " . $row["id"] . "   Name: " . $row["f_name"] . "</td>";
		echo "<td class='imagefont smooth'>&nbsp;   Image: <a href='" . $largeimage . $row["id"] . "'><img src=" . $image . $row["f_name"] . " width='50px' height='50px' /></a><a href='" . $deleteimage . $row["id"] . "'>$link Delete Image from database</a>$linkend&nbsp;</td>";
		if (3 === ($i % 4)) {
			echo "</tr>";
		}
		$i++;
	}
} else {
	echo "Current Images in Database:";
}
$conn->close();
echo '</table>';

?>

Open in new window


In the above, the first query works perfectly but the second one does not return any results
The records are in the database and the field names are correct
0
Comment
Question by:doctorbill
  • 4
6 Comments
 
LVL 7

Accepted Solution

by:
Gauthier earned 500 total points
Comment Utility
I'm not sure you can reuse the $conn once it is closed...
so remove the first $conn->close()
1
 

Author Comment

by:doctorbill
Comment Utility
I tried changing the second query to $conn2 but still no luck
0
 

Author Comment

by:doctorbill
Comment Utility
Sorry - managed to sort it
I know why the $conn2 did not work
I just realised that my dbconnect.php connections reference file did not have a reference to $conn2

All good now
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:doctorbill
Comment Utility
Your solution also works
0
 

Author Closing Comment

by:doctorbill
Comment Utility
Solution
0
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
The question could be stupid, but have you open a $conn2 connection to the database? Usually one includes a script with the db connection in every script which have to access the db, so you should hve only $conn available, not an $conn2...
What happens removing the first $conn->close() as Gauthier suggested above?
1

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now