Jump to content

Problem with a while statement and mysql


stubyh

Recommended Posts

Hi

  I am currently having problems with this line in the code below

[color=red]echo "<a href=\"".$row[url]."\"><img src=\"/banner/bannerimages/".$row[image]."\" alt=\"".$row[alt_title]."\" border=\"0\"></a>"; [/color]


what I am getting is

Notice: Use of undefined constant url - assumed 'url' in c:\websites\banner\index3.php on line 67

Notice: Use of undefined constant image - assumed 'image' in c:\websites\banner\index3.php on line 67

Notice: Use of undefined constant alt_title - assumed 'alt_title' in c:\websites\banner\index3.php on line 67


and then the banner is displayed normally with correct url, image and alt_title

your help would be much appreciated


code bellow formatting has been removed (tables):-

thanks

  stubyh



[code]
<?php

  // get the data from the database
require_once('Connections/banners.php');


// Number of records to show per page:
$display = 10;

// Determine how many pages there are.
if (isset($_GET['np'])) { // Already been determined.

$num_pages = $_GET['np'];

} else { // Need to determine.


    $get_ids_sql = "SELECT id, link AS url, alt_title, image FROM banners WHERE status = 'on'";
    $get_ids_res = mysql_query ($get_ids_sql);
    $get_ids_array = array();

    $row = mysql_fetch_array($get_ids_res, MYSQL_NUM);

$num_records = $row[0];

// Calculate the number of pages.
if ($num_records > $display) { // More than 1 page.
$num_pages = ceil ($num_records/$display);
} else {
$num_pages = 1;
}

} // End of np IF.



// create the page for real

while ($row = mysql_fetch_array($get_ids_res, MYSQL_ASSOC)) {


    echo "<a href=\"".$row[url]."\"><img src=\"/banner/bannerimages/".$row[image]."\" alt=\"".$row[alt_title]."\" border=\"0\"></a>";

}

// Make the links to other pages, if necessary.
if ($num_pages > 1) {

echo '<br /><p>';
// Determine what page the script is on.
$current_page = ($start/$display) + 1;

// If it's not the first page, make a Previous button.
if ($current_page != 1) {
echo '<a href="view_users.php?s=' . ($start - $display) . '&np=' . $num_pages . '">Previous</a> ';
}

// Make all the numbered pages.
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="view_users.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a> ';
} else {
echo $i . ' ';
}
}

// If it's not the last page, make a Next button.
if ($current_page != $num_pages) {
echo '<a href="view_users.php?s=' . ($start + $display) . '&np=' . $num_pages . '">Next</a>';
}

echo '</p>';

} // End of links section.
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/25935-problem-with-a-while-statement-and-mysql/
Share on other sites

thanks

have tried that and this

echo "<a href=\""{$row['url']}"\"><img src=\"/banner/bannerimages/"{$row['image']}"\" alt=\""{$row['alt_title']}"\" border=\"0\"></a>";

but still getting same results

mod -

also getting Parse error: parse error, unexpected '{', expecting ',' or ';' in c:\websites\banner\notables.php on line 42

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.