Jump to content

Recommended Posts

I am trying to have the data from my database display on a webpage the problem I am having is two fold one the

1.  picture number is not displaying in order 

2. how do I get the birth date to display in D- M -  Y  on webpage        the output displays  = 2007-05-11   

 

<?php

$con = mysql_connect("localhost","","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("sacredfa_sacred", $con);

 

$query = "SELECT picture_number, first_name, middle_name, first_family_name, second_family_name, birthdate, gender

          FROM child_info";

 

$result = mysql_query($query);

 

 

if(!$result)

{

  echo "There was a problem getting the data";

}

else if(!$result)

{

echo "There were no results";

}

else

{

    echo "<b><center>Children to be sponsored</center></b><br><br>\n";

    while($row = mysql_fetch_assoc($result))

    {

 

 

echo "<table border='1'>

<tr>

<th>Picture Number</th>

<th>First Name</th>

<th>Middle Name</th>

<th>First Family Name</th>

<th>Second Family Name</th>

<th>Birthdate</th>

<th>Gender</th>

</tr>";

 

while($row = mysql_fetch_array($result))

  {

  echo "<tr>";

  echo "<td>" . $row['picture_number'] . "</td>";

  echo "<td>" . $row['first_name'] . "</td>";

  echo "<td>" . $row['middle_name'] . "</td>";

  echo "<td>" . $row['first_family_name'] . "</td>";

  echo "<td>" . $row['second_family_name'] . "</td>";

  echo "<td>" . $row['birthdate'] . "</td>";

  echo "<td>" . $row['gender'] . "</td>";

  echo "</tr>";

  }

echo "</table>";

}

}

mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/
Share on other sites

<?php
$con = mysql_connect("localhost","","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("", $con);

$query = "SELECT picture_number, first_name, middle_name, first_family_name, second_family_name, birthdate, gender
          FROM child_info";
        
$result = mysql_query($query);


   if(!$result)
      {
             echo "There was a problem getting the data";
      }
   else if(!$result)
      {
         echo "There were no results";
      }
   else
      {
          echo "<b><center>Children to be sponsored</center></b><br><br>\n";
    while($row = mysql_fetch_assoc($result))
       {
      
         
echo "<table border='1'>
<tr>
<th>Picture Number</th>
<th>First Name</th>
<th>Middle Name</th>
<th>First Family Name</th>
<th>Second Family Name</th>
<th>Birthdate</th>
<th>Gender</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
        echo "<tr>";
        echo "<td>" . $row['picture_number'] . "</td>";
        echo "<td>" . $row['first_name'] . "</td>";
        echo "<td>" . $row['middle_name'] . "</td>";
        echo "<td>" . $row['first_family_name'] . "</td>";
        echo "<td>" . $row['second_family_name'] . "</td>";
        echo "<td>" . $row['birthdate'] . "</td>";
        echo "<td>" . $row['gender'] . "</td>";
        echo "</tr>";
  }
echo "</table>";
      }
}
mysql_close();
?>

A number of things:

1)  You removed your db password from this page, but I bet you didn't change it in your actual database.  You have told (according to the counter here), 35 strangers your database password, and it's indexed by google.  You must change it, now.

 

2)  Adding the ORDER BY that Muddy_Funster suggested will fix your ordering problem unless your picture number isn't stored properly in your database, but you'll have to define "didn't work" first.

 

3)  Formatting your date output can be done with date() and strtotime(), like so: date('d-m-Y', strtotime($row['birthdate']));

...

3)  Formatting your date output can be done with date() and strtotime(), like so: date('d-m-Y', strtotime($row['birthdate']));

but I formated the date for them too, i just forgot the _ in the middle of DATE_FORMAT() was all  :-[

I didn't even notice that.  Yes, everything muddy_funster said will fix all your problems if you put that underscore there.

yeah, your php is a bit of a mess: you seem to be doing everything twice: you have an elseif checking the same condition as the first if (not sure if you expect things to change from one line to the next, but they won't in this case) and then you nest your while loop for disply inside....well....a while loop for display, which is re-assigning different values to the same variables. I'm curious, cold you post a screen cap of what your actual output page looks like?

    while($row = mysql_fetch_assoc($result))

 

That line appears twice in your code.

 

If you indent your code properly, you'll be better able to notice redundancies like this (and the elseif mentioned earlier).  Remove the outer    while($row = mysql_fetch_assoc($result))

and your code will stop skipping the first result.

Write a page to display a single entry based on ID.  Use $_GET['id']

 

Link the page you already have to that page.  Add "?id={$row['picture_number']}" to the URL.

 

Come back when you're stuck on either of those steps.

 

please explain further

No.  if you need more help than this, you need to be taking a class or reading a book, not asking random people on the internet.  You've already made a page to display records, where did that come from?
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.