Jump to content

Oziam

Members
  • Posts

    44
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Oziam's Achievements

Member

Member (2/5)

0

Reputation

  1. Yep that does the trick nicely, Thanks for your help, this is a great solution, as you stated it has the benefit of being able to add more categories also. Cheers!
  2. Hello, I have a table with x amount of rows and each row holds data for a pic, it has various coulmns including a category coulmn, what I want to do is get the number of rows(listings) for each category, there are only seven categories(at the moment) and I have code that queries each row by cat name to get the result, I am doing this for each category name but there must be a more efficient solution! my current code is below; $q1 = "SELECT id FROM pics WHERE cat='category1'"; $r1 = mysql_query($q1) or die(mysql_error()); $cnt1 = mysql_num_rows($r1); $q2 = "SELECT id FROM pics WHERE cat='category2'"; $r2 = mysql_query($q2) or die(mysql_error()); $cnt2 = mysql_num_rows($r2); $q3 = "SELECT id FROM pics WHERE cat='category3'"; $r3 = mysql_query($q3) or die(mysql_error()); $cnt3 = mysql_num_rows($r3); // etc.... any suggestions would be appreciated! Thanks!!
  3. LOL, your'e joking, I can't believe how simple that was! Of course it makes sense! Cheers!
  4. I want to replace an EXACT match only, I have been using str_replace but that seems to replace any part of a string containing the match. e.g $string = "Andora And Fortitude Of Official"; $result = str_replace(array("And", "Of"), array("and", "of"), $string)."\n"; will return "andora and fortitude of official"; but what I want is "Andora and Fortitude of Official" so it replaces only the EXACT match And, Of with and, of Thanks!..
  5. Thanks, that does the trick nicely!
  6. It seems ereg is deprecated in php 5+ so what is a good alternative? Thanks!
  7. I worked out a solution, I was playing around and stumbled across it, I don't know why it works but it does 100% of the time, I have tested it using all variations of ranges and it outputs the correct value every time! New code! $rawip_from = '3716537112'-0; // adding the -0 or +0 will return a negative value of 221.133.219.-232 // raw to readable ip $w1 = (int)($rawip_from / 16777216) % 256; $x1 = (int)($rawip_from / 65536 ) % 256; $y1 = (int)($rawip_from / 256 ) % 256; $z1 = (int)($rawip_from ) % 256; if($z1 < 0){$z1 = $z1 + 256;} // include this to convert $z1 to the correct value $rawip_to = '3716537215'-0; // this will return a negative value of 221.133.219.-129 // raw to readable ip $w2 = (int)($rawip_to / 16777216) % 256; $x2 = (int)($rawip_to / 65536 ) % 256; $y2 = (int)($rawip_to / 256 ) % 256; $z2 = (int)($rawip_to ) % 256; if($z2 < 0){$z2 = $z2 + 256;} // include this to convert $z2 to the correct value $ip_from = ($w1.'.'.$x1.'.'.$y1.'.'.$z1); $ip_to = ($w2.'.'.$x2.'.'.$y2.'.'.$z2); echo "Ip range: $ip_from - $ip_to"; // Output: Ip range: 221.133.219.24 - 221.133.219.127 which is correct :-) It would be nice to understand why it works but hey I am just greatful it does!
  8. Oziam

    Question

    so something like; if($row1 == 'No' && $row2 == 'No'){ echo "$row1"; echo "$row2"; } elseif($row1 != 'No' && $row2 == 'No'){ echo "$row1"; } elseif($row1 == 'No' && $row2 != 'No'){ echo "$row2"; } etc...
  9. I have a simple script that converts an ip range to a readable ip address, e.g 2147483647 = 127.255.255.255 and it works fine up to this range, anything after this causes an incorrect ip address. e.g 2147483648 should be 128.0.0.0 but it outputs 128.0.0.255 and so all ip address after this are incorrect! code I am using is below; $rawip_from = '2147483648'; // raw to readable ip $w1 = (int)($rawip_from / 16777216) % 256; $x1 = (int)($rawip_from / 65536 ) % 256; $y1 = (int)($rawip_from / 256 ) % 256; $z1 = (int)($rawip_from ) % 256; $rawip_to = '2147549184'; // raw to readable ip $w2 = (int)($rawip_to / 16777216) % 256; $x2 = (int)($rawip_to / 65536 ) % 256; $y2 = (int)($rawip_to / 256 ) % 256; $z2 = (int)($rawip_to ) % 256; $ip_from = ($w1.'.'.$x1.'.'.$y1.'.'.$z1); $ip_to = ($w2.'.'.$x2.'.'.$y2.'.'.$z2); echo "Ip raw range: $rawip_from - $rawip_to<p>Ip range: $ip_from - $ip_to"; /* should output Ip raw range: 2147483648 - 2164260863 Ip range: 128.0.0.0 - 128.1.0.0 but it outputs 128.0.0.255 - 128.1.0.255 */ It always seems to add 255 to the last range instead of the correct value????? I heard there is a bug in php with integers > 2147483647 if anyone knows of a fix it would be great!! Thanks...
  10. Thanks for the hint! I have revised my code as you suggested and now it works 100% $i = 1; while($i <= 10){ $start = (1000 * $i); $end = ($start + 1000); $rows = null; $q1 = "SELECT * FROM table WHERE start >= '$start' AND end <= '$end' LIMIT 0,100"; $r1 = mysql_query($q1) or die(mysql_error()); while($a1 = mysql_fetch_array($r1, MYSQL_ASSOC)){ if(mysql_num_rows($r1) > 0){ $rows .= $a1['col1'].':'.$a1['col2']."\n";} } echo nl2br(trim($rows.'<p>')); $i++; }
  11. What I am trying to do is query a database using a loop conditional and return the data but my code only repeats the first instance multiple times! My code is below, I have tried to use comments to explain what should be happeing! $rows = null; $q1 = "SELECT * FROM table"; $r1 = mysql_query($q1) or die(mysql_error()); $i = 1; while($i <= 5){ $start = (1000 * $i); $end = ($start + 1000); while($a1 = mysql_fetch_array($r1, MYSQL_ASSOC)){ /* query the database where 'start' is >= 1000 and where 'end' is <= 2000, this should loop so the next time is where 'start' >= 1000 * $i should be 1000 then 2000, 3000 etc... and where 'end' should be 2000, 3000, 4000 etc... */ if($a1['start'] >= $start && $a1['end'] <= $end){ $rows .= $a1['col1'].':'.$a1['col2']."\n"; } } echo nl2br(trim($rows.'<p>')); $i++; } /* The problem is that it always shows multiple instances of the first result only where start = 1000 and end = 2000 */ Any help would be much appreciated!!
  12. Yeah that worked great! Thanks!
  13. HI, I have a table with over 100,000 rows, I want to query just one column and return the data for each different result but only once. In other words, say I have a column named col1, and it has approx 200 different entries in 100,000 rows, so some entries may have 100's of duplicates. I want to return ONLY 1 instance of each unique entry, so I should get 200 unique results not 100,000 with many duplicates. How to do this???? Thanks!
  14. I am using a script for users to download a file, however after the download I want to be able to redirect the user or display a message etc... but I cannot get it to work. My download code is below; if($do_download){ $filename = 'file.zip'; $itemfile = ('/abc/123/htdocs/bin/'.$filename); $filelength = filesize($itemfile); $fp = @fopen($itemfile, "rb"); ob_start(); Header("Pragma: public"); Header("Expires: 0"); Header("Cache-control: private"); Header("Content-Type: application/x-zip-compressed"); Header("Content-Transfer-Encoding: binary"); Header("Content-Length: $filelength"); Header("Accept-Ranges: bytes"); Header('Content-Disposition: attachment; filename="'.$filename.'"'); Header("Connection: close"); ob_end_clean(); while(!feof($fp)){ print stream_get_contents($fp); // for PHP 5+ else use fread } fclose($fp); header('Location: page2.php'); } It doesn't seem to matter what I do whether a redirect or just an echo command nothing continues after the file is downloaded????
  15. I mean if use the form field title and enter for example "Titlename (part 1)" it will skip the error, it will continue with the rest of the code and insert into database! Its got me #### ### EDIT ### Ok I found it! I was looking at the wrong script, in my other script it checks the title with !preg_match('/^([\'-_ a-z0-9]){2,50}$/i', $_POST['title']) notice the \' before the hyphen, this was to allow single quotes and this for some reason is causing the drama and allowing other characters to be included! If I remove the \' it works fine! Thanks for your help!
×
×
  • 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.