Solved

php query

Posted on 2016-07-30
6
29 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

773 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