Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php query

Posted on 2016-07-30
6
Medium Priority
?
37 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 2000 total points
ID: 41735757
I'm not sure you can reuse the $conn once it is closed...
so remove the first $conn->close()
1
 

Author Comment

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

Author Comment

by:doctorbill
ID: 41735762
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:doctorbill
ID: 41735763
Your solution also works
0
 

Author Closing Comment

by:doctorbill
ID: 41735766
Solution
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 41735770
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.
Suggested Courses

971 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