Page 1 of 1

how do i echo out my data from data base

Posted: Mon Nov 23, 2009 3:46 pm
by chris_s_22
i want to pull each data row and display on page
heres my code im using

Code: Select all

 
<?php
include_once 'Connect.php';
if (!is_authed()) 
{
     die ('You are not permitted to view this page, <a href="../index.php">click here</a> to go back.');
}
    $query = ("SELECT * FROM links ");
    $result= mysql_query ($query) or die ('Could not query.');
    while ($row = mysql_fetch_assoc($query))
    {
    $linkto = $row["linkto"];
    $src = $row["src"];
    $alt = $row["alt"];
    $width = $row["width"];
    $height = $row["height"];
    $text = $row["text"];
    }
?>
<html><head>
<link href="style.css" rel="stylesheet" type="text/css">
<script src="scripts/ShowHint.js" type="text/javascript"></script>
</head>
 
<body>
<div class=logo><?php include "logo.php";?></div>
<div class=navigationbarbox><?php include "navigationbar.php";?></div>
<div class=linkbanner><?php include "linkbanner.php";?></div>
<div class=linkform>
<a href="loginform.php">add a link</a>
 
 
 
 
<?php
echo "<a href="$linkto"><img src="$src" alt="$alt" width="$width" height="$height" border="0"></a><br>";
?>
</div>
 
 
 
 
 
<div class=footerbox><?php include "footer.php";?></div>
</body></html>

Re: how do i echo out my data from data base

Posted: Mon Nov 23, 2009 4:18 pm
by Jonah Bron
Replace your while loop above, with this:
$output = array();

Code: Select all

while ($row = mysql_fetch_assoc($query)) {
    $temp = array();
    $temp['linkto'] = $row['linkto'];
    $temp['linkto'] src = $row['src'];
    $temp['alt'] = $row['alt'];
    $temp['width'] = $row['width'];
    $temp['height'] = $row['height'];
    $temp['text'] = $row['text'];
    $output[] = $temp;
}
Then, you can create a table below in the body, and loop through $output with foreach.

Re: how do i echo out my data from data base

Posted: Mon Nov 23, 2009 9:05 pm
by ramblin54321
I think all you have to do is put your echo statement within your while loop. Don't forget single quotes.
Try this:
<?php
include_once 'Connect.php';
if (!is_authed())
{
die ('You are not permitted to view this page, <a href="../index.php">click here</a> to go back.');
}
?>
<html><head>
<link href="style.css" rel="stylesheet" type="text/css">
<script src="scripts/ShowHint.js" type="text/javascript"></script>
</head>
<body>
<div class=logo><?php include "logo.php";?></div>
<div class=navigationbarbox><?php include "navigationbar.php";?></div>
<div class=linkbanner><?php include "linkbanner.php";?></div>
<div class=linkform>
<a href="loginform.php">add a link</a>
<?php
$query = ("SELECT * FROM links ");
$result= mysql_query ($query) or die ('Could not query.');
while ($row = mysql_fetch_assoc($query))
{
$linkto = $row["linkto"];
$src = $row["src"];
$alt = $row["alt"];
$width = $row["width"];
$height = $row["height"];
$text = $row["text"];
echo "<a href='$linkto'><img src='$src' alt='$alt' width='$width' height='$height' border='0'></a><br>";
}
?>
</div>
<div class=footerbox><?php include "footer.php";?></div>
</body></html>

Re: how do i echo out my data from data base

Posted: Tue Nov 24, 2009 6:17 am
by chris_s_22
thx exactly what i wanted