Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php query

Posted on 2016-07-30
6
Medium Priority
?
35 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

721 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