gellnsh Posted March 17, 2009 Share Posted March 17, 2009 Hello all, I'm having a problem with my php code alerting me by email when my database is out of product. I'm getting a ton of emails stating that I have no products in certain categories but when I check my site I indeed have many products in that category. I'm wondering if the code is wrong? Following is the code I'm using: <? $hostname = ""; $username = ""; $password = ""; $userstable = ""; $dbName = ""; //some additional variables we need to display pages //number of results displayed on a page. Change this if u want... $limit = 16; //format-strings for the page-links //change it to ur needs (u may add some stylesheet-information), but be aware of the %d ´s. //They will be replaced by some values later. //Format for a page-link, if it links not to the current result-page $page_array_format = "<a href=\"".$PHP_SELF."?offset=%d\" >[%d]</a> "; //Format for a page-link, if it links to the current result-page (here it is not a link) $page_array_format_current_page = "%d "; //Format for the next-link $page_next_format = "<a href=\"".$PHP_SELF."?offset=%d\" >[next]</a> "; //Format for the back-link $page_back_format = "<a href=\"".$PHP_SELF."?offset=%d\" >[back]</a> "; //DO NOT CHANGE THIS... //offset point. Recordsets offset+limit are displayed $offset = (!empty($_REQUEST['offset'])) ? (int)$_REQUEST['offset'] : 0; /** * Function getPagesArray() * returns Pages-Array like this: * * Array { * 1 => array { * 'page' => 1, * 'page_offset' => 0 * } * 2 => array { * 'page' => 2, * 'page_offset' => 10 * } * } * * * @return array pages-array */ function getPageArray($hits, $range) { $pages = array(); $hits = (int)$hits; $range = (int)$range; //if there are more hits then range allows... if($hits > $range) { $page_number = $hits / $range; $number_of_pages = ceil($page_number); $offset = 0; for($i=1; $i<= $number_of_pages; $i++) { $pages[$i] = array('page' => $i, 'page_offset' => $offset); $offset += $range; } } return $pages; } function printPageArray($hits, $range) { global $page_array_format, $page_array_format_current_page, $page_back_format, $page_next_format, $offset, $limit; $offset = (int)$offset; $hits = (int)$hits; $pages = getPageArray($hits, $range); //var_dump($pages); //get the back-link if($offset > 0) { //if that is not the first page //show the back-link $back_offset = $offset - $limit; //should not be smaller then 0 ;-) $back_offset = ($back_offset < 0) ? 0 : $back_offset; //print formated back-link printf($page_back_format, $back_offset); } //get the page-links for($i=1; $i <= sizeof($pages); $i++) { if($pages[$i]['page_offset'] == $offset) { //thats the number of current page printf($page_array_format_current_page, $pages[$i]['page']); } else { //not the current page printf($page_array_format, $pages[$i]['page_offset'], $pages[$i]['page']); } } //get the next-link if(($offset + $limit) < $hits) { //if this is not the last page $next_offset = $offset + $limit; printf($page_next_format, $next_offset); } } //do the connection @MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); //choose the db @mysql_select_db( "$dbName") or die( "Unable to select database"); //first we need a simple query to get the number of all records $query = "SELECT * FROM $userstable WHERE ADVERTISERCATEGORY LIKE '%Lifestyle%'"; $hits = @mysql_num_rows(mysql_query($query)); //Now the real query, but now with LIMIT-Clause $query = "SELECT PRICE,RETAILPRICE,BUYURL,NAME,DESCRIPTION,IMAGEURL,IMPRESSIONURL FROM $userstable WHERE ADVERTISERCATEGORY LIKE '%Lifestyle%'"; $query.= " LIMIT $offset, $limit"; $result = MYSQL_QUERY($query); /* How many of these users are there? */ $number = @MYSQL_NUMROWS($result); /* Print these results to the screen in a nice format */ $i = 0; IF ($number == 0) : PRINT "<font size=\"2\">New Product Coming Soon!</font><br>"; $adminEmail = "[email protected]"; $subject = "The category called is no longer valid"; $body = "The category %Lifestyle% no longer has products in it. Page guitar-amps-gifts.php"; mail($adminEmail,$subject,$body,"FROM: $adminEmail"); ELSEIF ($number > 0) : PRINT ""; //Now its time to print out our pages-links PRINT "<p align=center>"; //where ever u put next line, there will be displayed the page-array printPageArray($hits, $limit); PRINT "</p>"; print '<table width="100%" border="2" cellspacing="5" cellpadding="10"><tr>'; $x = 1; echo "<tr>"; //start inside WHILE ($i < $number): $PRICE = mysql_result($result,$i,"PRICE"); $RETAILPRICE = mysql_result($result,$i,"RETAILPRICE"); $BUYURL = mysql_result($result,$i,"BUYURL"); $NAME = mysql_result($result,$i,"NAME"); $DESCRIPTION = mysql_result($result,$i,"DESCRIPTION"); $IMAGEURL = mysql_result($result,$i,"IMAGEURL"); $IMPRESSIONURL = mysql_result($result,$i,"IMPRESSIONURL"); //put td here PRINT '<td align="center" valign="top">'; PRINT "<strike><strong><font color=\"#FF0000\" size=\"2\">$RETAILPRICE</strike></strong></font><BR>"; PRINT "<strong><font color=\"#FF0000\" size=\"2\">$PRICE</font></strong><BR>"; PRINT "<a href=$BUYURL target=blank rel=nofollow><img src=$IMAGEURL border=0><BR></A>"; PRINT "<a href=$BUYURL><strong><font size=\"2\">$NAME</a></strong></font><BR>"; PRINT "<font size=\"2\">$DESCRIPTION</font><BR><BR>"; PRINT "<a href=$BUYURL><strong><font size=\"2\">MORE...</a></strong></font><BR><BR>"; PRINT "<a href=$IMPRESSIONURL></A>"; //wrap it //change where its 2,3,4 to 3,4,5 to display five in a row. - easy ha.. print "</td>"; if ($x == 2 ) {$x ++;} else { if ($x == 3 ) {$x ++;} else { if ($x == 4 ) {echo "</tr><tr>"; $x=1;} else{$x ++;} }} $i++; ENDWHILE; print "</tr>"; echo "</table>"; //Now its time to print out our pages-links PRINT "<p align=center>"; //where ever u put next line, there will be displayed the page-array printPageArray($hits, $limit); PRINT "</p>"; ENDIF; //if is at end ?> Any help would be very much appreciated. thanks EDITTED BY WILDTEEN88: Please wrap code within code tags ( ) when posting code. Link to comment https://forums.phpfreaks.com/topic/149862-php-alert-not-working/ Share on other sites More sharing options...
samshel Posted March 17, 2009 Share Posted March 17, 2009 $result = mysql_query($query) or die(mysql_error()); /* How many of these users are there? */ $number = mysql_num_rows($result) or die(mysql_error()); remove all error maskings "@" from your code they will hide all errors and you wont be able to debug quickly,, Link to comment https://forums.phpfreaks.com/topic/149862-php-alert-not-working/#findComment-787032 Share on other sites More sharing options...
gellnsh Posted March 17, 2009 Author Share Posted March 17, 2009 Hi samshel, Thanks for getting back to me. I'm pretty much a newbie so don't understand what you want me to do? Do you mean to remove all lines starting with "@"??? Link to comment https://forums.phpfreaks.com/topic/149862-php-alert-not-working/#findComment-787052 Share on other sites More sharing options...
samshel Posted March 17, 2009 Share Posted March 17, 2009 just remove the @ sign from start of all functions and write all mysql functions in lower case. also replace above lines in your code. Link to comment https://forums.phpfreaks.com/topic/149862-php-alert-not-working/#findComment-787140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.