Hello,

I have this code over here:

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Admin area - Sydcul URL Shortener</title>
<meta name="description" content="Free URL shortener">
<meta name="keywords" content="sydcul, url, shortener, tiny, url, tinyurl, bit, ly, bitly">
<meta name="author" content="Sydcul">
<link href="../stylesheet.css" rel="stylesheet" type="text/css">
<link rel="icon" type="image/ico" href="../favicon.ico">
</head>
<body>
<center>
<h1>Admin area - Sydcul URL Shortener</h1>
<h2>URLs:</h2>
<?php
include ('../config.inc.php');

$connection = mysql_connect($host, $user, $password);

mysql_select_db($database, $connection);

$urls = mysql_query("SELECT * FROM `" . $prefix . "urls`");
$array = mysql_fetch_array($urls);

if(!empty($array)) {

    echo('<table border="1"><tr><th>Short url</th><th>Long url</th><th>Actions</th></tr>');

    while($row = mysql_fetch_array($urls))
    {
        echo('<tr><td>http://short.sydcul.com/' . $row['shorturl'] .  '</td><td>' . $row['longurl'] . '</td><td><a href="delete.php?shorturl=' . $row['shorturl'] . '">Delete</a></td></tr>');
    }

    echo('</table>');
} else {
    echo('There are currently no shortened URLs. Create one using the homepage.');
}

mysql_close($connection);
?>
</center>
</body>
</html>

However, it is not showing the first item.

My DB:
13

And the output page:
21

This used to work at some point. I can't remember what I changed...

I tried using $array in the while-loop, but that shows GMail infinitely...

Member Avatar for Zagga

Hi,

The problem is because you are running 2 fetch-array requests on the same mysql result (lines 23 and 29).

Try resetting the array pointer after the first request. Add this to line 24.

mysql_data_seek($urls,0);

See http://php.net/manual/en/function.mysql-data-seek.php for details but don't forget to change from mysql to a safer/better alternative.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.