Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7896041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:47:28+00:00 2026-06-03T07:47:28+00:00

I have two issues:- Issue No :1 (PHP related) I can’t display an array

  • 0

I have two issues:-
Issue No :1 (PHP related)
I can’t display an array of images on a PHP page.Here is the code i am trying..
getUser.php

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'sulen', '123');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("holidayNet", $con);

$sql="SELECT * FROM image WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Picture</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['FirstName'] . "</td>";
  echo "<td>" . $row['LastName'] . "</td>";
  echo "<td>" . $row['Age'] . "</td>";
  echo "<td>" . $row['Hometown'] . "</td>";


  $dir = 'images';
$file_display = array('jpg','jpeg','png','gif');

if (file_exists ($dir) == false) {
    echo 'Directory \'', $dir, '\' not found!';
}
else{
    $dir_contents = scandir($dir);


    foreach($dir_contents as $file) {
        $file_type = strtolower(end(explode('.', $file)));

        If($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == 

true) {
            echo "<td>" . $row ['<img src="', $dir, '/', $file, '" alt="', $file, '" />'] . "</td>";

        }       

    }

}
  /*echo "<td>" . $row['Job'] . "</td>";*/
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?> 
<br />

one.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Sulman qb</option>
<option value="2">asd asd</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html>

Issue No 2 (AJAX Related)
You might have seen in the above code that while using AJAX i am retrieving image directory path from database. Now, how i am going to give that directory path to php file getUser.php or

$dir = 'images'(need that path here !);

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:47:30+00:00Added an answer on June 3, 2026 at 7:47 am

    this line is wrong:

     echo "<td>" . $row ['<img src="', $dir, '/', $file, '" alt="', $file, '" />'] . "</td>";
    

    why not just, also why are you using $row[] to display the image, $row is meant for retrieving the values in your database corresponding to the table field. $row[‘table field’];

    echo '<td>';
    echo '<img src =';
    echo $dir."/".$file;
    echo  '/>';
    echo '</td>';
    

    also try

    $dir = "images/";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the issue with this code? Here we have two files: classA.h and
I have two issues I'm trying to work though. The first is I'm trying
I'm using Subversion for one of my PHP projects. I have two questions/issues: How
my issue is that i have two ajax calls to php for a registration
I have a very strange issue on my hands. I have two IIS websites
I have found many people with simliar issues but no soultions...basically I have two
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
I have the following issue: A java object contains two arrays of core datastore
been struggling with an issue now for a day or two. I have an
I have made a simple test application for the issue, two winforms each containing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.