Jump to content

iblood

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Everything posted by iblood

  1. iblood

    Better method

    here's what I will do in this kinds of situation <?php $q1 = "select ItemID, sum(Rating) as mr from dd_rating group by ItemID order by mr desc limit 0,4"; $r1 = mysql_query($q1) or die(mysql_error()); $q2parts = array(); while($a1 = mysql_fetch_array($r1)) { $q2parts[] = "ItemID = '$a1[0]'"; } $q2results = array(); if (!empty($q2parts)) { $q2 = "select ItemTitle from dd_items where ".implode(' OR ', $q2parts); $r2 = mysql_query($q2) or die(mysql_error()); while($a2 = mysql_fetch_array($r2)){ $q2results = $a2; } } ?> I'm pretty sure there's some workaround using SQL joins, but I'm just not a fan of JOINS.
  2. It happens, because, when you got back to page 1, the page generated a random results again. I'm not sure what would be the disadvantages of this, but maybe you could try to cache your db results, then do the paging via PHP. <?php if (!isset($_SESSION['results'])) { $_SESSION['results'] = $all_of_your_rendomized_records; } else { $all_of_your_rendomized_records = $_SESSION['results']; } // then handle your $all_of_your_rendomized_records's pagination here using php ?> Im not sure though the disadvantages of this, if this will cosume much memory or something. But I think it can handle with just 600 records.
  3. I don't think you're using the function correct. I checked the php manual:http://php.net/manual/en/control-structures.foreach.php, however, I can't find an example like your implementation. Maybe it could help if you would post what you are trying to achieve here, and what your array variable contains.
  4. I believe you're gonna need to use FQL for this. This might help. http://developers.facebook.com/docs/reference/fql/link_stat/
  5. I think all you need is like this:?? $queryVars = array(); foreach ($row as $k => $v) { $queryVars[] = $k . '=' . urlencode($v); } $row['postcode_link'] = "<p class=link><a href='/gmap.php?" . implode('&', $queryVars) . "'>Map</a></p><br>"; you just replace this code: if( !empty($row['postcode']) ) { $row['postcode_link'] = "<p class=link><a href='/gmap.php?postcode=" . urlencode($row['postcode']) . "'>Map</a></p><br>"; }
  6. $sqlcond = ''; foreach ($checkbox as $checkboxes) { $sqlcond .= 'SID=' . $checkbox . ' OR '; } if ($sqlcond !== '') { // Get all teachers with SIDs $sql = "SELECT `TID` FROM `TEACHERS_SUBJECTS` WHERE " . rtrim($sqlcond, ' OR '); $res = mysql_query($sql); // Create a buffer of teachers $teachers = array(); while ($row = mysql_fetch_assoc($res)){ $teachers[$row['TID']][] = 1; } $tnameSqlExt = ''; foreach ($teachers as $tid => $t) { // check if teacher has all the SID from checkbox if (count($t) == count($checkbox)){ // at this point we are sure that the teacher has all the SID requested $tnameSqlExt .= 'TID=' . $tid . ' OR '; } } // display teachers names if ($tnameSqlExt !== '') { $tSql = "SELECT `NAME` FROM `TEACHERS` WHERE " . $tnameSqlExt; $res = mysql_query($tSql); while ($row = mysql_fetch_assoc($res)){ echo $row['NAME'] . '<br />'; } } } Hope this workd
  7. I think you missed Nodral's point here At the end of this script, $_SESSION will always have the value of the last record.. Regarding your implementation, I would recommend to just use $_GET instead of $_SESSION. something like: //if ("{$row['passState']}" == 0) {echo "<a href='check.php'>Check your answers.</a><br />\n";} if ("{$row['passState']}" == 0) {echo "<a href='check.php?quiztitle=". urlencode($quizTitle) ."'>Check your answers.</a><br />\n";} and in your check.php: //$quizTitle = $_SESSION['quizTitle']; $quizTitle = mysql_real_escape_string($_GET['quizTitle']);
×
×
  • 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.