jcbones
Staff Alumni-
Posts
2,653 -
Joined
-
Last visited
-
Days Won
8
Everything posted by jcbones
-
Simple code error, can't find out why it echo's out two times
jcbones replied to 3raser's topic in PHP Coding Help
Uhm....didn't understand that. And they are already in my if statement? And why do quotes matter? o.O Quotes matter, because PHP will look for the CONSTANT with that name, when it finds none, then it will try to convert it to a string. All of this eats up processing time, which slows the script down. This is completely overlooking the fact that quotes is the correct way of doing it. -
You can return the results of each user, but you would have to have multiple queries, or select the group, and count the users via an array. Mysql will only return 1 row for a count(). Try: $select = mysql_query("SELECT usergroupid, userid FROM vb_user AS u CROSS JOIN vb_post AS p USING(userid) WHERE dateline > UNIX_TIMESTAMP(CURDATE() - INTERVAL 30 DAY) AND u.usergroupid = 22 GROUP BY u.usergroupid") or die(mysql_error()); while ($list = mysql_fetch_array($select)) { $store[$list['usergroupid']][$list['userid']] += 1; } foreach($store as $k => $v) { echo 'User Group: ' . $k . '<br />'; foreach($v as $kk => $vv) { echo $kk . ' has ' . $vv . ' post in the past thirty days.<br />'; } }
-
Calling a function in a class from within that same class?
jcbones replied to ChrisMartino's topic in PHP Coding Help
?? When calling a class function from within the same class, you always use $this->class_function(); Of course, the class will not create it's object until you call the class. -
My take on this script; <?php function get_grade((int)$i) { if($i > 79) return 'A'; elseif($i > 69 && $i < 80) return 'B'; elseif($i > 59 && $i < 70) return 'C'; elseif($i > 49 && $i < 60) return 'D'; elseif($i > 39 && $i < 50) return 'E'; else return 'F'; } $adno = $_GET['adno']; $select = mysql_query("select * from acadinfo where adno='$adno'") or die('<p>Error Retrieving<br/>'.'Error: ' .mysql_error() . '</p>'); echo "<table width='548' border='1'> <tr> <th width='26' scope='col'>ADMISSION NO.</th> <th width='26' scope='col'>MATHEMATICS</th> <th width='26' scope='col'>ENGLISH</th> <th width='26' scope='col'>PHYSICS</th> <th width='26' scope='col'>CHEMISTRY</th> <th width='365' scope='col'>BIOLOGY</th> </tr> <tr><td scope='row'>$adno</td>"; $datalist = mysql_fetch_assoc($select); foreach($datalist as $data){ echo '<td>' . get_grade($data) . '</td>'; } echo '</tr></table>'; ?>
-
substr() strlen() $_SERVER['vars']
-
Are the tables column size sufficient to carry the data you are trying to retrieve? Or, is the title longer than 50 characters?
-
You must be including these files into other files. Move: session_start(); To the very top of the parent file. On both files.
-
Did you start the session in index.php? session_start();
-
<?php $filter = "2"; $input = array("1", "2", "3", "4"); unset($input[array_search($filter,$input)]); $rand_keys = array_rand($input); ?>
-
Date - how to get the current date in certain place.
jcbones replied to oh_boy123's topic in PHP Coding Help
I'm not sure if I'm understanding correctly. You want to change the default timezone of your scripts? So that when you insert a date into the database, it will reflect your time and not the servers time? date_default_timezone_set('Asia/Hong_Kong'); -
Un-tested, but you can try: <?php $query = "SELECT * FROM images WHERE is_published!=1"; $result = mysql_query ($query); // Run the query while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { $images_not_published[] = $row['image_id']; } function getRandomImage($dir,$type='random') { global $errors,$seed,$images_not_published; if (is_dir($dir)) { $fd = opendir($dir); $images = array(); while (($part = @readdir($fd)) == true) { if ( @eregi("(gif|jpg|png|jpeg)$",$part) ) { $images[] = $part; } } $images = array_values(array_diff($images,$images_not_published)); // adding this in case you want to return the image array if ($type == 'all') return $images; if ($seed !== true) { mt_srand ((double) microtime() * 1000000); $seed = true; } $key = mt_rand (0,sizeof($images)-1); return $dir . $images[$key]; } else { $errors[] = $dir.' is not a directory'; return false; } } $image = getRandomImage('uploaded_images/'); echo "<img src='$image' width='519' height='353' border='0' usemap='#Map' \>"; ?>
-
Temp table is deleted -- Do I need to use cookies?
jcbones replied to mrherman's topic in PHP Coding Help
The biggest problem using Temp MySQL tables in a PHP script, is the tables are destroyed when the script completes, as the mysql connection automatically closes. Thus the MySQL session expires. -
You are attempting to use the function for a use it wasn't designed for. This function is design to pass a directory full of images to it, and it will select a random image from that directory. You are trying to give it an image name, but I don't know how you expect it to return a random image from that. Instead try: <?php //this is the file for all the function function getRandomImage($dir,$type='random') { global $errors,$seed; if (is_dir($dir)) { $fd = opendir($dir); $images = array(); while (($part = @readdir($fd)) == true) { if ( @eregi("(gif|jpg|png|jpeg)$",$part) ) { $images[] = $part; } } // adding this in case you want to return the image array if ($type == 'all') return $images; if ($seed !== true) { mt_srand ((double) microtime() * 1000000); $seed = true; } $key = mt_rand (0,sizeof($images)-1); return $dir . $images[$key]; } else { $errors[] = $dir.' is not a directory'; return false; } } $image = getRandomImage('uploaded_images/'); echo "<img src='$image' width='519' height='353' border='0' usemap='#Map' \>"; ?>
-
It may, although it will sort alphabetically, besides I like giving people more for their money.
-
Sorry, didn't notice the arrangement of the keys in OP. <?php $tank[0] = "User1"; $tank[1] = ""; $tank[2] = ""; $tank[3] = "User2"; $tank = array_filter($tank); sort($tank); echo '<pre>'; print_r($tank); echo '</pre>'; ?>
-
Try this. It may not be exactly what you are looking for, but should get you started in the general direction. Edit your $sql line for the right table and columns of course. <?php $sql = "SELECT * FROM `table` ORDER BY `timestamp` DESC"; $result = mysql_query($sql); if(mysql_num_rows($result)) { while($r = mysql_fetch_assoc($result)) { $side = ($r['IsGood'] == 1) ? 'Good' : 'Bad'; $arr[$side][] = $name; } $startGood = (is_array($arr['Good'])) ? 1 : 0; $startBad = (is_array($arr['Bad'])) ? 1 : 0; echo '<table border="1"><th>Good Team</th><th>Bad Team</th>'; if($startGood === 1) { foreach($arr['Good'] as $k => $v) { echo '<tr><td>' . $v . '</td>'; echo (isset($arr['Bad'][$k])) ? '<td>' . $arr['Bad'][$k] . '</td>' : '<td> </td>'; echo '</tr>'; } } elseif($startBad === 1) { foreach($arr['Bad'] as $k => $v) { echo '<tr><td> </td><td>' . $v . '</td></tr>'; } } else { die('Error.'); } echo '</table>'; } else { echo 'There are no players present.'; } ?>
-
Funny, I just tried it, and it did. <?php $tank[0] = "User1"; $tank[1] = ""; $tank[2] = ""; $tank[3] = "User2"; echo '<pre>'; print_r(array_filter($tank)); echo '</pre>'; ?>
-
This is simply stating that on line 24: The index of 'id' in the array $_GET doesn't exist. Which then causes your SQL to fail. Building line 24 so that it would always have an id would be the proper way show the page. $id = (isset($_GET['id'])) ? (int)$_GET['id'] : 1;
-
I know I gave you this code a couple of days ago, when I was running on nothing but a couple monster drinks, and 1 hour sleep. But: foreach(file('networkmap.asp.htm') as $cleared) { Should have been foreach($file as $cleared) { And your strip_content was from the strip_tags function. After saying all of that, if $ping is null, it should still be listed as an empty value using explode. Since, the comma(,) should still be there. So if $status is equal to 'DOWN' then $ping should be empty().
-
The HTML page (now is PHP and should be named with the .php extension) <?php session_start(); $name = null; $customer_mail = null; $customer_phone = null; $piano_make_and_model = null; $piano_size = null; $stairs = null; $estimated_mileage = null; $truck_access = null; $other_details = null; $customer_email = null; if(isset($_SESSION['errors']) && is_array($_SESSION['errors'])) { foreach($_SESSION['errors'] as $error => $desc) { $error = strtolower(str_replace(' ','_',$error)); $$error = '<br />' . $desc; } } ?> <h3>Want a free quote? Take a moment to fill out our form!</h3> <table width="650" border="0" cellpadding="0" cellspacing="1"> <tr> <td><form name="form1" method="post" action="send_contact.php"> <table width="100%" border="0" cellspacing="3" cellpadding="3"> <tr> <td style="width:200px">Name</td> <td>:</td> <td><input name="name" type="text" id="name" size="50"/><?php echo $name; ?></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="customer_mail" type="text" id="customer_mail" size="50"/><?php echo $customer_email; ?></td> </tr> <tr> <td>Phone Number</td> <td>:</td> <td><input name="phone" type="text" id="phone" size="50"/><?php echo $customer_phone; ?></td> </tr> <tr> <td>Make & Model of Piano</td> <td>:</td> <td><input name="make" type="text" id="make" size="50"/><?php echo $piano_make_and_model; ?></td> </tr> <tr> <td>Size of Piano (measured)</td> <td>:</td> <td><input name="size" type="text" id="size" size="50"/><?php echo $piano_size; ?></td> </tr> <tr> <td>Number of stairs</td> <td>:</td> <td><input name="stairs" type="text" id="stairs" size="50"/><?php echo $stairs; ?></td> </tr> <tr> <td>Mileage traveled from A to B</td> <td>:</td> <td><input name="mileage" type="text" id="mileage" size="50"/><?php echo $estimated_mileage; ?></td> </tr> <tr> <td>Truck Access (Yes/No)?</td> <td>:</td> <td><input name="access" type="text" id="access" size="50"/><?php echo $truck_access; ?></td> </tr> <tr> <td>Any other information we may need to know?</td> <td>:</td> <td><textarea name="detail" cols="50" rows="4" id="detail"></textarea><?php echo $other_details; ?></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit"/> <input type="reset" name="Submit2" value="Reset"/></td> </tr> </table> </form> </td> </tr> </table> processing script. Put your complete URI to the page above in the header function on line 33. <?php session_start(); // Contact subject $subject ="Customer Quote Form"; // Details $name = (isset($_POST['name'])) ? strip_tags(ucwords(strtolower($_POST['name']))) : NULL; // Mail of sender $mail_from= (isset($_POST['customer_mail'])) ? strip_tags($_POST['customer_mail']) : NULL; $info['Name'] = $name; $info['Customer Phone'] = (isset($_POST['phone'])) ? strip_tags($_POST['phone']) : NULL; $info['Piano Make and Model'] = (isset($_POST['make'])) ? strip_tags($_POST['make']) : NULL; $info['Piano Size'] = (isset($_POST['size'])) ? strip_tags($_POST['size']) : NULL; $info['Stairs'] = (isset($_POST['stairs'])) ? (int) $_POST['stairs'] : NULL; $info['Estimated Mileage'] = (isset($_POST['mileage'])) ? (int) $_POST['mileage'] : NULL; $info['Truck Access'] = (isset($_POST['access']) && strtolower($_POST['access']) == 'yes') ? 'Yes' : 'No, or not stated.'; $info['Other Details'] = (isset($_POST['detail'])) ? strip_tags($_POST['detail']) : NULL; $info['Customer Email'] = (isset($_POST['customer_mail'])) ? strip_tags($_POST['customer_mail']) : NULL; $message = NULL; foreach($info as $key => $value) { if($value == NULL) { $error[$key] = 'You have left ' . $key . ' blank.'; } $message .= $key . ': ' . $value . PHP_EOL; } if(is_array($error) && isset($error)) { $_SESSION['errors'] = $error; header('Status: 200'); header('Location: http://www.mysite/myform.php'); } // From $header="from: $name <$mail_from>"; // Enter your email address $to ='<my email here>'; $send_contact=mail($to,$subject,$message,$header); // Check, if message sent to your email // display message "We've recived your information" if($send_contact){ header('Status: 200'); header('Location: thankyou.php'); //This should be a full URI as in 'Location: http://mysite.com/thankyou.php' } else { $comment = "Error: Please email us directly: <customer email here>."; } ?><!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 content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Contact Form</title> </head> <body> <?php echo $comment; ?> </body> </html> Of course, you will want to style the error messages for display. Currently this puts them below the inputs the error resides in.
-
Don't feel bad, I've looked at that manual until my eyes bleed, and I still missed it.
-
Mysql is most likely confused on which tables ID you want. Try: SELECT dg.* FROM detail dg JOIN userlist dp ON dg.username=dp.username WHERE dg.province='Austin' LIMIT 0, 5
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Our Survey Page</title> <meta name="Keywords" content="" /> <meta name="Description" content="" /> <link href="default.css" rel="stylesheet" type="text/css" /> </head> <BODY > <DIV align="left"><p><br /> <strong>Survey Results.<br /><br /> <?php $dbhost = '*****'; $dbuser = '******'; $dbpass = '******'; $dbname = 'mySurvey'; $tableval = 'Survey'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to database'); mysql_select_db($dbname); @mysql_select_db("$dbname") or die("Error: Unable to select database"); $query="SELECT * FROM ".$tableval." "; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $fname=$row[fullname]; $gender=$row[gender]; $answer1=$row[answer1]; $answer2=$row[answer2]; $answer3=$row[answer3]; $answer4=$row[answer4]; $answer5=$row[answer5]; $answer6=$row[answer6]; $answer7=$row[answer7]; $answer8=$row[answer8]; $answer9=$row[answer9]; $comments=$row[comments]; $html = <<<HTML <TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="800"> <TR><TD WIDTH="800"> <br> <TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0"> <TR> <TD WIDTH="4"> </TD> <TD > </TD> <TD ><TABLE CELLPADDING="5" CELLSPACING="6" BORDER="0"> <TR> <TD VALIGN="middle"> <FONT ><b>Respondent"s Name:</b>{$fullname} </FONT></TD> <TR> <TD VALIGN="middle"> <FONT ><b>Respondent"s Sex:</b>{$gender} </FONT></TD> <TR> <TD VALIGN="middle"> <FONT > <B>1) Is this your first online training program at the School of Library and Information Sciences?</B><BR> {$answer1} </FONT> </TD> <TR> <TD VALIGN="middle"> <FONT > <B>2) Overall, how positive were your collaborative learning experiences with<br> the School of Library and Information Sciences?</B><BR>{$answer2} </FONT> </TD> <TR> <TD VALIGN="middle"> <FONT > <B>3) How easy or difficult has it been for you to communicate<br> your thoughts or opinions to the teacher?</B><BR>{$answer3} </FONT> </TD> <TR> <TD VALIGN="middle"> <FONT > <B>4) Rate the technical knowledge of the teacher who worked with you</B><BR>{$answer4} </FONT> </TD> <TR> <TD VALIGN="middle"> <FONT > <B>5) How Accessible is the teacher</B><BR>{$answer5} </FONT> </TD> <TR> <TD VALIGN="middle"> <FONT > <B>6) If you have collaborated with a group, how easy or difficult has it been for groups<br> you have worked in to agree on a time to meet?</B><BR>{$answer6} </FONT> </TD> <TR> <TD VALIGN="middle"> <FONT > <B>7) The School of Library and Information Sciences<br> has provided several materials to support our learning</B><BR>{$answer7} </FONT> </TD> <TR> <TD VALIGN="middle"> <FONT > <B> Online learning at the School of Library and Information Sciences has been a great experience</B><BR>{$answer8} </FONT> </TD> <TR> <TD VALIGN="middle"> <FONT > <B>9) Overall, I will take another online traing at The School of Library<br> and Information Sciences again</B><BR>{$answer9} </FONT> </TD> <TR> <TD VALIGN="middle"> <FONT > <B>10) What do you like most about the School of Library and Information Sciences?</B><BR>{$comments} </FONT> </TD> HTML; echo $html; } echo ' </TABLE> </TD> <TD> </TD> </TR></TABLE> </TD></TR> </TABLE> </BODY> </HTML>'; ?>
-
A simple work around would be. <?php $array1 = array("dog" => "brown", "cat" => "white"); $array2 = array("dog" => "black", "duck" => "white") ; foreach($array1 as $key => $value) { $array3[$key][] = $value; } foreach($array2 as $key => $value) { $array3[$key][] = $value; } echo '<pre>'; print_r($array3); echo '</pre>'; ?>
-
<?php $file = file("networkmap.asp"); foreach(file('networkmap.asp') as $value) { // Strip HTML formatting $content = strip_tags($value); $strip_content = substr($content, 34); list($router,$metric,$ping,$status)=explode(",",$strip_content); echo $router; echo $metric; echo $ping; echo ($status == 'UP') ? '<img src="green.png" alt="up" />' : '<img src="red.png" alt="down" />'; echo '<hr />'; } ?>