jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
If the loop doesn't run, then neither does any code inside the loop. Although, in theory you could do. $registered=safe_query("'"); $num = mysql_num_rows($registered); while($dd=mysql_fetch_array($registered)) { if($num == 0) die(); ... } Although, I don't know why you would want to.
-
This may help you with your project. Although, I don't suggest a copy/paste approach, rather a read/learn approach.
-
Is tstamp a date column? if so, you should have links made like. <a href="?month=02">Feb</a> Then you can: $month = (int)$_GET['month']; $sql = "SELECT * FROM `news` WHERE month(tstamp) = '$month'";
-
I suppose you are logging a unix timestamp for each chat entry. You would then need to define a timestamp when a user logs in, and not display any chat messages that occurred before that timestamp. //user logs in if(isset($_SESSION['timestamp'])) { $time = $_SESSION['timestamp']; } else { $time = $_SESSION['timestamp'] = time(); } $sql = "SELECT * FROM `chat` WHERE `room` = '$room_id' AND `time` > '$time'"; Or, something along those lines.
-
What sort of things would they do?
-
Told PHP parser to ignore the next character.
-
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'
jcbones replied to mrbean's topic in PHP Coding Help
26. echo "<b>Betaling Voltooid!!!</b><br>Je hebt nu een <b><FONT COLOR=\"blue\">vip</FONT><b> account!!!<br>U kunt nu dit venster sluiten<br>Succes nog met spelen!!<br><br><br>PS Je word automatisch door gestuurt naar je hoofdkwartier"; -
I got the month and year on it's own row like you wanted. I also made some notations that should help you get it nailed down. Feel free to ask for more help if needed. <?php echo "<a href='http://table_cal.php/'>Today</a> is: "; echo(date("l\, F dS Y") . "<br /><br />"); echo "<table border='1'>"; $Number = 1; //Suggestion: seperate month and year for access to them later. $Month = date("F"); $Year = date('Y'); $Month_number = date('n'); //Edited the next line (JcBones) echo "<tr><td colspan=\"7\" align=\"center\">$Month $Year</td></tr>"; echo '<tr>'; echo "<td>Sunday</td>"; echo "<td>Monday</td>"; echo "<td>Tuesday</td>"; echo "<td>Wednesday</td>"; echo "<td>Thursday</td>"; echo "<td>Friday</td>"; echo "<td>Saturday</td>"; '</tr>'; //Suggestion: date('t') gets the days in the month. $days_in_month = date('t'); //Suggestion: Get the first day of the month. $first_day_of_month = date('l',mktime(0,0,0,$Month_number,1,$Year)); //You need to incorporate the above variables in order to get the //calendar to show the right dates on the right days. //IE. The first day of May was on a Saturday. for ($Row = 0; $Row < 6; $Row++) {echo '<tr>'; for ($Column= 0; $Column < 7; $Column++) {echo "<td>$Number</td>";; $Number++; } echo '</tr>'; } echo "</table>"; ?>
-
<?php //page time: session_start(); if(!isset($_SESSION['time'])) { $_SESSION['time'] = time(); } else { if(isset($_SESSION['failed'])) { echo 'You have failed to complete this test in a timely manner.'; } elseif((time() - $_SESSION['time']) > 180) { echo 'Timer has run out!'; unset($_SESSION['time']); $_SESSION['failed'] = 1; } } Or, something along those lines.
-
echo '<a href="'.$_SERVER['PHP_SELF'].'?state=' . $id . '&startrow='.($startrow+10).'">Next</a>'; Try that.
-
Use "return" instead of "echo" function array2fieldtest ($data) { //var_dump($data) ; //$element_count = count ($data) ; foreach ($data as $ky) { $key = key ($data) ; $keys[] = $key ; next ($data) ; } $fields = 'id, ' . implode (', ', $keys) ; return nl2br ("$fields\n") ; }
-
Did you happen to look at these lines? $id=$_GET['state']; $start = (isset($_GET['startrow'])) ? (int)$_GET['startrow'] : 0; ini_set ("display_errors", "1"); error_reporting(E_ALL); $sqlCommand = "SELECT * FROM COUNTIES where state = '$id' LIMIT $start, 10"; $result = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
-
The users computer. Cookies are always on the end users computer. Unlike Sessions which is on your web server.
-
$id=$_GET['state']; $start = (isset($_GET['startrow'])) ? (int)$_GET['startrow'] : 0; ini_set ("display_errors", "1"); error_reporting(E_ALL); $sqlCommand = "SELECT * FROM COUNTIES where state = '$id' LIMIT $start, 10"; $result = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); $fields_num = mysqli_num_fields($result); echo "<h1>Test Table</h1>"; echo "<table border='1'><tr>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysqli_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysqli_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysqli_free_result($result); if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) { $startrow = 0; } else { $startrow = (int)$_GET['startrow']; } echo '<a href="'.$_SERVER['PHP_SELF'].'?startrow='.($startrow+10).'">Next</a>'; ?>
-
I hope not, I wrote that myself about a year ago. Although, I looked at around 1,000 (it seems) paganate scripts before I got my head wrapped around it. So if something is similar, I'm sorry. Not intentional in the least. But, I would like to see it, have a link?
-
$_COOKIE will return an empty array, if $_COOKIE is not set. if(!empty($_COOKIE)) { echo '<pre>'; print_r($_COOKIE); echo '</pre>'; } else { echo 'There are no Cookies, you must bake some.'; }
-
foreach() Should be all you need.
-
$sql = "SELECT * FROM `table` WHERE `date` < CURDATE()";
-
You need at most 2 queries with paganation. You have way more than that, and are even running queries inside a foreach() loop. I've changed the page a good bit, you may want to run this script without over writing your current page. class.pagAnate.php class pagAnate { private $numberPerPage; private $sql; public $page; private $count; private $numberOfPages; public $PageNav; public $limit; function __construct($sql, $perPage, $url = NULL) { $this->page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1; $this->numberPerPage = $perPage; $this->url = $url; //sets the first part of the url, ONLY if you are using mod_rewrite. $this->sql = $sql; $this->getPages(); } private function getPages() { if(isset($this->sql)) { $q = mysql_query($this->sql); if(mysql_num_rows($q) > 0) { $r = mysql_fetch_row($q); $this->count = $r[0]; } } if(isset($this->count)) { $this->numberOfPages = ceil($this->count/$this->numberPerPage); } $this->setPageNumber(); } private function setPageNumber() { $this->page = ($this->page > $this->numberOfPages) ? $this->numberOfPages : $this->page; $this->page = ($this->page < 1) ? 1 : $this->page; $this->setLimit(); } private function setLimit() { $this->limit = 'LIMIT ' .($this->page - 1) * $this->numberPerPage .',' .$this->numberPerPage; $this->setNav(); } private function setNav() { $this->url = ($this->url == NULL) ? '?page=' : $this->url . '/page/'; if($this->count > $this->numberPerPage) { $nav = ($this->page == 1) ? ' FIRST PREV '."\n" : '<a href="' . $this->url . '1">FIRST</a> <a href="' . $this->url . ($this->page - 1) . '">PREV</a>' . "\n"; $nav .= ' ( Page ' . $this->page . ' of ' . $this->numberOfPages . ' ) '; $nav .= ($this->page == $this->numberOfPages) ? " NEXT LAST " : '<a href="' . $this->url . ($this->page + 1) . '">NEXT</a> <a href="' . $this->url . $this->numberOfPages . '">LAST</a> '; $this->PageNav = $nav; } else { $this->PageNav = NULL; } } } Your page <?php ob_start(); session_start(); ?><!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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="styles/main.css" rel="stylesheet" type="text/css" /> <title>All About The Music [ Search ]</title> <style type="text/css"> <!-- body { background-color: #FF9900; background-image: url(images/pagebg.png); } html {scrollbar-face-color: black; scrollbar-shadow-color: orange; scrollbar-highlight-color: orange; scrollbar-3dlight-color: black; scrollbar-darkshadow-color: black; scrollbar-track-color: orange; scrollbar-arrow-color: orange; } div.scroll { height: 360px; width: 880px; overflow: auto; padding: 8px; } .style1 {color: #FFFFFF} --> </style> </head> <body> <table width="950" border="0" align="right"> <tr> <td><div align="right"> <?php //include 'top.php'; ?> </div></td> </tr> </table> <p> </p> <p> </p> <p> </p> <table width="950" height="592" border="0" align="center"> <tr> <td height="588" background="images/searchbg.png"><table width="900" height="536" border="0" align="center"> <tr> <td colspan="3"><p align="center"><img src="images/header.png" width="421" height="65" /></p> <form action='search.php' method='GET'> <div align="center"> <input type='text' size='40' name='search' /> <input type='submit' name='submit' value='Search' /> </div> </form></td> </tr> <tr> <td height="385" colspan="3"><div class='scroll' valign='top'> <?php mysql_connect("localhost","root",""); mysql_select_db("site"); include('class.pagAnate.php'); //get data $button = $_GET['submit']; $search = $_GET['search']; $start = $_GET['start']; if (!$button) echo "<div id='plaintext'>Your didnt submit a keyword</div>"; else { if (strlen($search)<=2) echo "<div id='plaintext'>Search term too short.</div>"; else { echo "<div id='plaintext'>You searched for <b>$search</b></div>"; mysql_connect("localhost","root",""); mysql_select_db("site"); //explode search term $search_exploded = explode(" ",$search); $construct = 'SELECT * FROM music WHERE'; foreach($search_exploded as $search_each) { $keyword[] = " keywords LIKE '%$search_each%'"; } $construct .= implode(' OR ',$keyword) . 'ORDER BY ID DESC'; $pages = new pagAnate(str_replace('*','COUNT(ID)',$construct),5); if($pages->count==0) echo "<div id='plaintext'>No results found.</div>"; else { echo "<div id='plaintext'>{$pages->count} results found!<p><hr COLOR='orange'><p></div>"; $run = mysql_query($construct . $pages->limit); while($runrows = mysql_fetch_assoc($run)) { $name = $runrows['name']; $whouploaded = $runrows['uploadedby']; $location = $runrows['location']; echo "<table width='880px' style='border: 1px solid orange; padding: 3px;' border='0'> <tr> <td width='370px'> <div id='plaintext'>$name</div> </td> <td width='200px'> <script language='JavaScript' src='player/audio-player.js'></script> <object type='application/x-shockwave-flash' data='player/player.swf' id='audioplayer1' height='24' width='200'> <param name='movie' value='player/player.swf'> <param name='FlashVars' value='playerID=audioplayer1&soundFile=songs/$location'> <param name='quality' value='high'> <param name='menu' value='false'> <param name='wmode' value='transparent'> </object> </td> <td> <div id='plaintext'>Uploaded By: $whouploaded</div> </td> </tr> </table><p>"; } } } } ?> </div></td> </tr> <tr> <td width="262" height="21"> <?php echo str_replace('page','search=$search&submit=Search&page',$pages->PageNav); ?> </td> <td width="421"> </td> <td width="262"> </td> </tr> </table> </td> </tr> </table> </body> </html>
-
Another take. foreach($units_total as $units_row) { $clientname = $units_row['clientname']; $unit = $units_row['unit']; $units = $units_row['units']; $units_all += $units; //$units_list .= "<li>".$clientname." - ".$units." ".$unit."</li>"; //Set the information to an array. $clients[$clientname][$unit] += $units; } if(is_array($clients)) { foreach($clients as $name => $v) { //Rip out the name of the client. $units_list .= '<li>' . $name . ' - '; //set an integer so we know how many tier2 //values we have read. $i = 0; foreach($v as $unit => $units) { //if this is the more than the first tier2 values, use a '+' between the units. $units_list .= (++$i > 1) ? ' + ' . $units . ' ' . $unit : $units . ' ' . $unit; } //close the line out. $units_list .= '</li>'; } }
-
<?php $result = mysql_query("SELECT * FROM Animals"); $url='.../animals/'; $numofrows = mysql_num_rows($result); while($row = mysql_fetch_array($result)){ echo "<td><img src='".$url.$row['photoAnimal']."' height='100px' width='100px'>"; echo "<br>"; echo "<a href='http://www.cool.com/animal.php?animal={$row['nameAnimal']}'>{$row['nameAnimal']}</a></td>"; } ?>
-
Is your hosting on a windows server?
-
Moving on to the next FOREACH via IF statement inside FUNCTION?
jcbones replied to Dismal_Bliss's topic in PHP Coding Help
SOMETHING RIGHT HERE TO IGNORE EVERYTHING THAT FOLLOWS AND MOVE ONTO THE NEXT EMAIL IN MY "FOREACH" LOOP = return; -
As Zach pointed out, you have named a page "config_page.php" and included it as "config.php". So, no $_SESSION variables were set.