General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old January 29th, 2003, 09:02 AM
Snowfruit Snowfruit is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Ireland
Posts: 11 Snowfruit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
On/off working code :(

This is the code

PHP Code:
<?
srand
((double)microtime()*1000000);

$conn mysql_connect("localhost","uname","pword") or die("Unable to connect to database");
$db mysql_select_db("irelandbnb") or die("Unable to select database irelandbnb");
if(
$town=="all"$query 'select * from data where `county`="'.$county.'"'
else 
$query 'select * from data where `county` = "'.$county.'" and `town` = "'.$town.'"';
$result mysql_query($query);
$max mysql_num_rows($result);

if(!isset(
$seed)){
    
$seed rand(1$max);
    
$i $seed;
    
$j 0;
    
$page 1;
}
else {
    
$i $last;
    
$j 0;
}

//To fill town select box
$query1 "select * from data where `county`=\"".$county."\""
$result1 mysql_query($query1);
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Ireland bed and breakfast</title><link rel="stylesheet" type="text/css" href="style/ibnb.css">
</head>
<body>
<div align="center"><img src="graphics/top.gif" alt="Ireland Bed and Breakfast" width="750" height="92" border="0"><br>
<table align="center" width="750" cellspacing="0" cellpadding="0" border="0">
<tr align="center" bgcolor="#0080c0">
<td><a title="Home" href="index.html" class="menu">Home</a></td>
<td><a href="glossary.html" class="menu" title="Glossary of Terms">Glossary</a></td>
<td><a class="menu" title="Car Rental Ireland" href="http://www.irish-car-rental.com" target="_blank">Car Rental</a></td>
<td><a class="menu" title="Membership details" href="membership.html" target="_blank">Membership</a></td>
<td><a class="menu" title="About us" href="about.html">About Us</a></td>
<td><a title="Tourism and Leisure in Ireland" href="http://www.insightwebmarketing.com" target="_blank" class="menu">Insight Network</a></td>
</tr>
</table>
<table align="center" width="750" cellspacing="0" cellpadding="15" border="0" bgcolor="#ffffff" style="padding-top: 10px;">
<tr>
<td align="center" width="600" valign="height" class="ban"><a href="properties.html">
<sxcript language="JavaScript" src="http://www.insight-intermark.com/banad/ads.pl?jscript" type="text/javascript"></script>
</td>
<td rowspan="3" valign="middle" width="150">
<a href="html/index.html"><img src="graphics/space.gif" alt="Dublin Accommodation Ireland" width="125" height="1" border="0"></a><br>
<sxcript language="JavaScript" src="http://www.insight-intermark.com/buttons/ads.pl?jscript">
</script><br><br>
<sxcript language="JavaScript" src="http://www.insight-intermark.com/buttons/ads.pl?jscript"></script><br><br>
<sxcript language="JavaScript" src="http://www.insight-intermark.com/buttons/ads.pl?jscript"></script><br><br>
<sxcript language="JavaScript" src="http://www.insight-intermark.com/buttons/ads.pl?jscript"></script><br><br>
<sxcript language="JavaScript" src="http://www.insight-intermark.com/buttons/ads.pl?jscript"></script><br><br></td>
</td>
</tr>
<tr>
<td align="center" width="512" valign="middle" class="ban">
<?php
echo '<form name=select action="list.html" style="margin-bottom: -3px">';
echo 
'<input type="hidden" name="county" value="'.$county.'">';
echo 
'<select name="town" style="width: 400px;color:red;" onchange="document.select.submit()">';
echo 
'<option> Search Another Town Here';
$towns = array("");
while (
$myrow mysql_fetch_row($result1)) {
    if(!
in_array($myrow[2], $towns)) {
        
$x end($towns);
        
$towns[$x] = $myrow[2];
        echo 
"<option>".$myrow[2]; }
    }
?>
</select></form>
</td></tr>
<tr>
<td> 
<table align="center" cellspacing="0" cellpadding="6" border="0" width="100%" class="head"><tr>
<?
if(($page*10)<=$max) echo '<th align="left">You are viewing properties '.(($page*10)-9).' - '.($page*10).' of  '.$max.'.</th>';
else echo 
'<th align="left">You are viewing properties '.(($page*10)-9).' - '.$max.' of  '.$max.'.</th>';
if(
$page>1) {
    echo 
'<th align="left"><a href="'.$PHP_SELF.'?page='.($page-1).'&county='.$county.'&town='.$town.'&seed='.$seed;
    
$a $i-10;
    if(
$a 0){
        
$a $max+$a;
        echo 
'&last='.$a.'" class="head"><- Previous</a></th>';
    }
    else echo 
'&last='.$a.'" class="head"><- Previous</a></th>';
}
if(
$page<($max/10)) {
    echo 
'<th align="right"> <a href="'.$PHP_SELF.'?page='.($page+1).'&county='.$county.'&town='.$town.'&seed='.$seed;
    
$a $i+10;
    if(
$a $max){
        
$a $a-$max;
        echo 
'&last='.$a.'" class="head">Next -></a></th>';
    }
    else 
'&last='.$a.'" class="head">Next -></a></th>';
}
echo 
'</tr></table>';
//-----------------------------------
echo '<table align="center" cellspacing="0" cellpadding="6" border="0" width="100%" class="thbs"><tr>';
do {
    if(
$i == $max+1$i 1;
    if(
$town == "all"$query 'select * from data where `id`="'.$i.'" and `county`="'.$county.'"';
    else 
$query 'select * from data where `id`="'.$i.'" and `county`="'.$county.'" and `town`="'.$town.'"';
    
$res mysql_query($query);
    
$row mysql_fetch_row($res);
    echo 
"
    <td rowspan='2' width='100' class='small' align='center'>
    <a href='display.html?id=$row[19]'>
    <img src='thumbs/$row[10]' alt='Click for further details' width='100' height='66' border='0'>
    <br>Further details here</a></td>
    <td class='thbs2' width='320'>$row[18], $row[2]</td>
    <td rowspan='2' width='38' valign='middle' class='thbs3'>
    <a href='display.html?id=$row[19]'>
    <img src='graphics/moreinfo.gif' width='36' height='36' alt='Click here for further details' border='0'></a></td>
    </tr><tr>
    <td class='small'>
    <img src='graphics/space.gif' alt='' width='1' height='56' border='0' align='right'>$row[9]</td>
    </tr>"
;
    
$i++;
    
$j++;
} while((
$j 10) && ($i != $seed));
$j 0;
$page++;
echo 
'</table>';
?>
</td>
</tr>
</table>
<table width="750" align="center" border="0" cellspacing="0">
<tr>
<td class="hf" width="24">
<a href="mailto:michael"insightwebmarketing.com"> <img src="graphics/email.gif" alt="Email Us" width="14" height="10" hspace="10" border="0"></a>
</td>
<td class="hf">
<a href="http://www.insightwebmarketing.com" class="hf" title="Click for Ireland\'s Internet Marketing Agency for Tourism & Leisure"> 
Copyright © 1995 - <script language=JavaScript>var today=new Date();
var year=today.getFullYear();
document.write(year);</script> - Insight Web Marketing Ltd - Killarney</a>
</td>
<td class="hf" width="24">
<a href="aboutus.html"><img src="graphics/info.gif" alt="About Insight Web Marketing" width="14" height="14" hspace="10"  border="0"></a> 
</td>
</tr>
</table>
</body>
</html>


Now what its meant to do:
It picks a random number ($seed) between 1 and the last record in the query. It then displays 10 records per page until all the records that fit in the query have been shown.

It worked for a little while except that my previous and next buttons weren't working. So I fixed that and since then I have had the following two problems:
1) Records 14 and 16 are never displayed :roll: even though they are deffinetly present in the database, and they were always shown before....

2) The random sort works fine for one $town but for the rest it just displays blank cells.....

Help Please!!!

Reply With Quote
  #2  
Old January 29th, 2003, 03:19 PM
ramz ramz is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Juiz de Fora - MG- Brazil
Posts: 93 ramz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to ramz Send a message via MSN to ramz
Hi!
Have you tried using the ORDER BY RAND() for this?!
__________________
Regards,
Ramiro Varandas Jr.

Reply With Quote
  #3  
Old January 30th, 2003, 04:22 AM
Snowfruit Snowfruit is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Ireland
Posts: 11 Snowfruit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes i have tried oreder by rand() and that works fine, but only for the first page, because on subsequent pages you either lose the sort or, if you resort, you have a good chance of redisplaying records that were already displayed on previous pages.

I think my solution above is the best way of doing it except that i get some strange and inconsistent behaviour. the strange I can handle but inconsistant is just plain confusing...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > On/off working code :(


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway