PHP - Using Get_class Feels "wrong"...
Hi Guys, still new to OOP. What I'm trying to achieve is quite straightforward and I've had some success, however, it feels "wrong" how I'm implementing the classes I have created which makes me feel I have a design problem or there is a better way to achieve what I want which right now I cannot see.
The task is quite clear, I receive a numerical user_id, after setting up the DB connection I pass it to a factory which executes a few queries and then generates an array of objects, the array will hold the objects relevant to what the person has been, i.e. has been a player, has been a coach, referee or whatever (when I pass the id I obviously have no idea of the role a person has held, it may be player only, it could be player and coach, etc).
My person class is extended to specific roles, player, referee, coach etc and obviously the array of returned objects enables me to access the properties required.
The issue is during implementation I obviously need to know what objects I have as to what methods I can call. So attempting $my_person->refGame will throw an error if $my_person is only holding a player object.
So my imlementation is along the lines of this the moment..
$my_person= PersonFactory::createPerson($database, $person_id); // my_person can be an array of objects, getName from parent class valid for all objects $details = $my_person[0]->getName(); // We need to know what class we have returned to call specific methods... foreach($my_person as $dis_array){ if (get_class($dis_array) == 'Player'){echo "I've been a player"; $my_person[0]->playerMethod; etc} if (get_class($dis_array) == 'Manager'){echo "I've been a manager"; $my_person[1]->somemanagerMethod; etc} if (get_class($dis_array) == 'Referee'){echo "I've been a Ref"; $my_person[2]->refMethod} }Really using the if block to identify the classes returned feels wrong. I feel like I'm missing something here, how should I be handling a returned array of objects in implementation? Also accessing each object via $my_person[0] (player) or $my_person[1] (manager) is wrong in implementation. Any help much appreciated. Edited by mich2004, 29 May 2014 - 07:23 AM. Similar Tutorialswhen trying to call
get_class($this)it will return the namespace of my class Application\Models\User_Model But what im really after is just User_Model... is there a way of actually getting the class name and not the namespace itself? thought i'd ask before making a class for that...thank you I am querying... $sql = "SELECT `messages_inbox`.`message_id`, `users`.`firstname`, `users`.`lastname`, `users`.`username` AS `from`, '${user_info['username']}' AS `to`, `subject`, LENGTH(`files`) AS `len`, 'inbox' AS `box`, DATE_FORMAT(`messages_inbox`.`time` ,'%T %D-%M-%Y') AS `time` "; $sql .= "FROM `messages_inbox` INNER JOIN `users` ON `messages_inbox`.`from_id` = `users`.`id` WHERE `to_id` = ${user_info['uid']} AND `messages_inbox`.`deleted` = 0 ORDER BY `messages_inbox`.`message_id` DESC"; and I am trying to output $displayName = ucwords("${message['firstname']} ${message['lastname']}"); by using $messages = pm_fetch_all($_GET['box']); I know my fetch works but for some reason firstname and lastname are only returning the logged in users first name and last name, not the person who sent the message. Code: [Select] <!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>Send Data Form</title> </head> <body> <?php if(!$_POST) exit; $email = $_POST['Email']; $name = $_POST['Name']; $telephone = $_POST['Telephone']; $comments = $_POST['Comments']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $errors=1; } if($errors==1) echo $error; else{ $values = array ('Name','Email','Telephone','Comments'); $required = array('Name','Email','Telephone','Comments'); $your_email = "****************"; $email_subject = "Comment posted from website:"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'Name' && $key != 'Comments' && $key != 'Telephone') { if( empty($_POST[$value]) ) { echo 'Please go back and complete all fields, thank you.'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } } $headers = "From: $email\r\n"."Reply-To: $email\r\n".'X-Mailer: PHP/' . phpversion(); mail($your_email, $email_subject, $email_content, $headers); if($send_contact){ echo "Thank you for your submission"; } else { echo "ERROR, your comment was not sent"; ?> </body> </html> MOD EDIT: [code] . . . [/code] tags added. mysql_query("UPDATE categories SET active=0 WHERE id=$id"); What am I doing wrong here to get: Parse error: syntax error, unexpected T_STRING ??? Here is code I have, I can't seem to figure this error out, I bet it is obvious, but I clearly am not seeing it..... Here is error: Problem with the query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3 (not really that good of an error, but maybe help getting started?) Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid' LIMIT 1"); while($row = mysql_fetch_array($sql)){ $name = $row["name"]; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; } // Set error message as blank upon arrival to page $errorMsg = ""; // First we check to see if the form has been submitted if (isset($_POST['name'])){ $name = ereg_replace("[^A-Z a-z0-9]", "", $_POST['name']); // filter everything but numbers and letters $phone = ereg_replace("[^A-Z a-z0-9]", "", $_POST['phone']); // filter everything but spaces, numbers, and letters $username = ereg_replace("[^A-Z a-z0-9]", "", $_POST['username']); // filter everything but spaces, numbers, and letters $address = ereg_replace("[^A-Z a-z0-9]", "", $_POST['address']); // filter everything but spaces, numbers, and letters $city = ereg_replace("[^A-Za-z0-9]", "", $_POST['city']); // filter everything but lowercase letters $state = ereg_replace("[^A-Za-z0-9]", "", $_POST['state']); // filter everything but lowercase letters $zip = ereg_replace("[^A-Za-z0-9]", "", $_POST['zip']); // filter everything but lowercase letters $cell = ereg_replace("[^A-Za-z0-9]", "", $_POST['cell']); // filter everything but lowercase letters $accounttype = ereg_replace("[^A-Z a-z0-9]", "", $_POST['accounttype']); // filter everything but lowercase letters $email = stripslashes($_POST['email']); $email = strip_tags($email); $email = mysql_real_escape_string($email); $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters // Check to see if the user filled all fields with // the "Required"(*) symbol next to them in the join form // and print out to them what they have forgotten to put in if((!$name) || (!$username) || (!$password)){ $errorMsg = "You did not submit the following required information!<br /><br />"; if(!$name){ $errorMsg .= "--- Name"; } else if(!$username){ $errorMsg .= "--- Username"; } else if(!$Password){ $errorMsg .= "--- Password"; } } else { // Database duplicate Fields Check $sql_username_check = mysql_query("SELECT userid FROM members WHERE username='$username' LIMIT 1"); $username_check = mysql_num_rows($sql_username_check); if ($username_check > 0){ $errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another."; } else { // Add MD5 Hash to the password variable $hashedPass = md5($password); // Add user info into the database table, claim your fields then values $sql = mysql_query("INSERT INTO members (name, phone, username, address, city, state, zip, cell, email, accounttype, password ) VALUES('$name','$phone','$username','$address','$city','$state','$zip','$cell','$email','$accounttype','$hashedPass'") or die ("Problem with the query: $sql<br>" . mysql_error()); printf("Records updated: %d\n", mysql_affected_rows()); echo mysql_error(); echo '<meta HTTP-EQUIV="REFRESH" content="3; url=http://final.net46.net/success.php">'; exit(); // Exit so the form and page does not display, just this success message } // Close else after database duplicate field value checks } // Close else after missing vars check //Close if $_POST } ?> I have all error reporting turned on. And no errors are showing. I've been staring at this code for 2 hours and can't find the error. But the form is blank! The form shows up with the radio buttons but is blank! Heres the code... <?php error_reporting(E_ALL); ?> <?php include 'dbc.php'; //----------------------------------------- $result = mysql_query("SELECT * FROM users ORDER BY nc_points DESC"); while ($row = mysql_fetch_object($result)) { $leaderboard[] = $row->user_name; $leaderboardPoints[] = $row->cfb_points; } $result1 = mysql_query("SELECT CollegeFootballGames.ID, CollegeFootballGames.Week, CollegeFootballGames.Away, CollegeFootballGames.Home, CollegeFootballTeams.Team FROM CollegeFootballGames INNER JOIN CollegeFootballTeams ON CollegeFootballGames.Away = CollegeFootballTeams.ID || CollegeFootballGames.Home=CollegeFootballTeams.ID"); while ($row = mysql_fetch_object($result1)) { $GameID[] = $row->ID; $Teams[] = $row->Team; } //---------------------------------------- $date =("now"); if ( strtotime($date) > strtotime('18 July 2010') && strtotime($date) < strtotime('2 September 2010')){$wknum = '1'; $wk = "Week";} elseif ( strtotime($date) > strtotime('6 September 2010') && strtotime($date) < strtotime('11 September 2010')){$wknum = '2'; $wk = "Week";} elseif ( strtotime($date) > strtotime('11 September 2010') && strtotime($date) < strtotime('16 September 2010')){$wknum = '3'; $wk = "Week";} elseif ( strtotime($date) > strtotime('18 September 2010') && strtotime($date) < strtotime('23 September 2010')){$wknum = '4'; $wk = "Week";} elseif ( strtotime($date) > strtotime('25 September 2010') && strtotime($date) < strtotime('2 October 2010')){$wknum = '5'; $wk = "Week";} elseif ( strtotime($date) > strtotime('2 October 2010') && strtotime($date) < strtotime('9 October 2010')){$wknum = '6'; $wk = "Week";} elseif ( strtotime($date) > strtotime('9 October 2010') && strtotime($date) < strtotime('16 October 2010')){$wknum = '7'; $wk = "Week";} elseif ( strtotime($date) > strtotime('16 October 2010') && strtotime($date) < strtotime('23 October 2010')){$wknum = '8'; $wk = "Week";} elseif ( strtotime($date) > strtotime('23 October 2010') && strtotime($date) < strtotime('28 October 2010')){$wknum = '9'; $wk = "Week";} elseif ( strtotime($date) > strtotime('30 October 2010') && strtotime($date) < strtotime('4 November 2010')){$wknum = '10'; $wk = "Week";} elseif ( strtotime($date) > strtotime('6 November 2010') && strtotime($date) < strtotime('13 November 2010')){$wknum = '11'; $wk = "Week";} elseif ( strtotime($date) > strtotime('13 November 2010') && strtotime($date) < strtotime('20 November 2010')){$wknum = '12'; $wk = "Week";} elseif ( strtotime($date) > strtotime('20 November 2010') && strtotime($date) < strtotime('27 November 2010')){$wknum = '13'; $wk = "Week";} else{} //Form 12 $form12 = ('<h3><em style="color: #F00"> <?php echo $wk;?> <?php echo $wknum;?> </em></h3> <form name="Picks" method="post" action="<?php echo $process; ?>"> <p><br> <input name="P0" type="hidden" value="<?php echo ($p[0]); ?>"> <label> <input type="radio" name="game1" value="<?php echo ($away[0]);?>" > <?php echo ($away[0]);?></label> at <label> <input type="radio" name="game1" value="<?php echo ($home[0]);?>" > <?php echo ($home[0]);?></label> <br> <input name="P1" type="hidden" value="<?php echo ($p[1]); ?>"> <label> <input type="radio" name="game2" value="<?php echo ($away[1]);?>" > <?php echo ($away[1]);?></label> at <label> <input type="radio" name="game2" value="<?php echo ($home[1]);?>" > <?php echo ($home[1]);?></label> <br> <input name="P2" type="hidden" value="<?php echo ($p[2]); ?>"> <label> <input type="radio" name="game3" value="<?php echo ($away[2]);?>" > <?php echo ($away[2]);?></label> at <label> <input type="radio" name="game3" value="<?php echo ($home[2]);?>" > <?php echo ($home[2]);?></label> <br> <input name="P3" type="hidden" value="<?php echo ($p[3]); ?>"> <label> <input type="radio" name="game4" value="<?php echo ($away[3]);?>" > <?php echo ($away[3]);?> </label> at <label> <input type="radio" name="game4" value="<?php echo ($home[3]);?>" > <?php echo ($home[3]);?></label> <input name="P4" type="hidden" value="<?php echo ($p[4]); ?>"> <br> <label> <input type="radio" name="game5" value="<?php echo ($away[4]);?>" > <?php echo ($away[4]);?></label> at <label> <input type="radio" name="game5" value="<?php echo ($home[4]);?>" > <?php echo ($home[4]);?></label> <br> <input name="P5" type="hidden" value="<?php echo ($p[5]); ?>"> <label> <input type="radio" name="game6" value="<?php echo ($away[5]);?>" > <?php echo ($away[5]);?></label> at <label> <input type="radio" name="game6" value="<?php echo ($home[5]);?>" > <?php echo ($home[5]);?></label> <br> <input name="P6" type="hidden" value="<?php echo ($p[6]); ?>"> <label> <input type="radio" name="game7" value="<?php echo ($away[6]);?>" > <?php echo ($away[6]);?></label> at <label> <input type="radio" name="game7" value="<?php echo ($home[6]);?>" > <?php echo ($home[6]);?></label> <br> <input name="P7" type="hidden" value="<?php echo ($p[7]); ?>"> <label> <input type="radio" name="game8" value="<?php echo ($away[7]);?>" > <?php echo ($away[7]);?></label> at <label> <input type="radio" name="game8" value="<?php echo ($home[7]);?>" > <?php echo ($home[7]);?></label> <br> <input name="P8" type="hidden" value="<?php echo ($p[8]); ?>"> <label> <input type="radio" name="game9" value="<?php echo ($away[8]);?>" > <?php echo ($away[8]);?> </label> at <label> <input type="radio" name="game9" value="<?php echo ($home[8]);?>" > <?php echo ($home[8]);?></label> <br> <input name="P9" type="hidden" value="<?php echo ($p[9]); ?>"> <label> <input type="radio" name="game10" value="<?php echo ($away[9]);?>" > <?php echo ($away[9]);?> </label> at <label> <input type="radio" name="game10" value="<?php echo ($home[9]);?>" > <?php echo ($home[9]);?></label> <br> <input name="P10" type="hidden" value="<?php echo ($p[10]); ?>"> <label> <input type="radio" name="game11" value="<?php echo ($away[10]);?>" > <?php echo ($away[10]);?></label> at <label> <input type="radio" name="game11" value="<?php echo ($home[10]);?>" > <?php echo ($home[10]);?></label> <br> <input name="P11" type="hidden" value="<?php echo ($p[11]); ?>"> <label> <input type="radio" name="game12" value="<?php echo ($away[11]);?>" > <?php echo ($away[11]);?></label> at <label> <input type="radio" name="game12" value="<?php echo ($home[11]);?>" > <?php echo ($home[11]);?></label> <br> <br> <label> <input type="reset" name="button" id="button" value="Reset"> </label> <label> <input type="submit" name="button2" id="button2" value="Submit"> </label> <br> </p> </form>'); if ( strtotime($date) > strtotime('18 July 2010') && strtotime($date) < strtotime('2 September 2010')){$wknum = '1'; $formDisplay = $form12; $wk = "Week"; $process = 'cfb_picks_process.php'; $away =array("$Teams[0]","$Teams[2]","$Teams[4]","$Teams[6]","$Teams[8]","$Teams[10]","$Teams[12]","$Teams[14]","$Teams[16]","$Teams[18]","$Teams[20]","$Teams[22]"); $home =array("$Teams[1]","$Teams[3]","$Teams[5]","$Teams[7]","$Teams[9]","$Teams[11]","$Teams[13]","$Teams[15]","$Teams[17]","$Teams[19]","$Teams[21]","$Teams[23]"); $p = array ("$GameID[0]","$GameID[2]","$GameID[4]","$GameID[6]","$GameID[8]","$GameID[10]","$GameID[12]","$GameID[14]","$GameID[16]","$GameID[18]","$GameID[20]","$GameID[22]");} elseif ( strtotime($date) > strtotime('6 September 2010') && strtotime($date) < strtotime('11 September 2010')){$wknum = '2';$formDisplay = $form12; $wk = "Week";$process = 'cfb_picks_process.php'; $away =array("$Teams[24]","$Teams[26]","$Teams[28]","$Teams[30]","$Teams[33]","$Teams[34]","$Teams[36]","$Teams[38]","$Teams[40]","$Teams[42]","$Teams[44]","$Teams[46]"); $home =array("$Teams[25]","$Teams[27]","$Teams[29]","$Teams[31]","$Teams[32]","$Teams[35]","$Teams[37]","$Teams[39]","$Teams[41]","$Teams[43]","$Teams[45]","$Teams[47]"); $p = array ("$GameID[24]","$GameID[26]","$GameID[28]","$GameID[30]","$GameID[32]","$GameID[34]","$GameID[36]","$GameID[38]","$GameID[40]","$GameID[42]","$GameID[44]","$GameID[46]"); } elseif ( strtotime($date) > strtotime('11 September 2010') && strtotime($date) < strtotime('16 September 2010')){$wknum = '3';$formDisplay = $form12; $wk = "Week";$process = 'cfb_picks_process.php'; $away =array("$Teams[49]","$Teams[50]","$Teams[52]","$Teams[55]","$Teams[56]","$Teams[58]","$Teams[61]","$Teams[62]","$Teams[64]","$Teams[66]","$Teams[68]","$Teams[70]"); $home =array("$Teams[48]","$Teams[51]","$Teams[53]","$Teams[54]","$Teams[57]","$Teams[59]","$Teams[60]","$Teams[63]","$Teams[65]","$Teams[67]","$Teams[69]","$Teams[71]"); $p = array ("$GameID[48]","$GameID[50]","$GameID[52]","$GameID[54]","$GameID[56]","$GameID[58]","$GameID[60]","$GameID[62]","$GameID[64]","$GameID[66]","$GameID[68]","$GameID[70]"); } elseif ( strtotime($date) > strtotime('18 September 2010') && strtotime($date) < strtotime('23 September 2010')){$wknum = '4';$formDisplay = $form12; $wk = "Week";$process = 'cfb_picks_process.php'; $away =array("$Teams[72]","$Teams[74]","$Teams[76]","$Teams[78]","$Teams[80]","$Teams[83]","$Teams[85]","$Teams[87]","$Teams[88]","$Teams[91]","$Teams[92]","$Teams[94]"); $home =array("$Teams[73]","$Teams[75]","$Teams[77]","$Teams[79]","$Teams[81]","$Teams[82]","$Teams[84]","$Teams[86]","$Teams[89]","$Teams[90]","$Teams[93]","$Teams[95]"); $p = array ("$GameID[72]","$GameID[74]","$GameID[76]","$GameID[78]","$GameID[80]","$GameID[82]","$GameID[84]","$GameID[86]","$GameID[88]","$GameID[90]","$GameID[92]","$GameID[94]"); } elseif ( strtotime($date) > strtotime('25 September 2010') && strtotime($date) < strtotime('2 October 2010')){$wknum = '5';$formDisplay = $form12; $wk = "Week";$process = 'cfb_picks_process.php'; /*$away =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $home =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $p = array ("$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]"); */} elseif ( strtotime($date) > strtotime('2 October 2010') && strtotime($date) < strtotime('9 October 2010')){$wknum = '6';$formDisplay = $form12; $wk = "Week";$process = 'cfb_picks_process.php'; /*$away =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $home =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $p = array ("$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]"); */} elseif ( strtotime($date) > strtotime('9 October 2010') && strtotime($date) < strtotime('16 October 2010')){$wknum = '7';$formDisplay = $form12;$wk = "Week";$process = 'cfb_picks_process.php'; /*$away =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $home =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $p = array ("$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]"); */} elseif ( strtotime($date) > strtotime('16 October 2010') && strtotime($date) < strtotime('23 October 2010')){$wknum = '8';$formDisplay = $form12;$wk = "Week";$process = 'cfb_picks_process.php'; /*$away =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $home =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $p = array ("$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]"); */} elseif ( strtotime($date) > strtotime('23 October 2010') && strtotime($date) < strtotime('28 October 2010')){$wknum = '9';$formDisplay = $form12;$wk = "Week";$process = 'cfb_picks_process.php'; /*$away =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $home =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $p = array ("$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]"); */} elseif ( strtotime($date) > strtotime('30 October 2010') && strtotime($date) < strtotime('4 November 2010')){$wknum = '10';$formDisplay = $form12;$wk = "Week";$process = 'cfb_picks_process.php'; /*$away =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $home =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $p = array ("$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]"); */} elseif ( strtotime($date) > strtotime('6 November 2010') && strtotime($date) < strtotime('13 November 2010')){$wknum = '11';$formDisplay = $form12;$wk = "Week";$process = 'cfb_picks_process.php'; /*$away =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $home =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $p = array ("$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]"); */} elseif ( strtotime($date) > strtotime('13 November 2010') && strtotime($date) < strtotime('20 November 2010')){$wknum = '12';$formDisplay = $form12;$wk = "Week";$process = 'cfb_picks_process.php'; /*$away =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $home =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $p = array ("$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]"); */} elseif ( strtotime($date) > strtotime('20 November 2010') && strtotime($date) < strtotime('27 November 2010')){$wknum = '13';$formDisplay = $form12;$wk = "Week";$process = 'cfb_picks_process.php'; /*$away =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $home =array("$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]","$Teams[]"); $p = array ("$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]","$GameID[]"); */} else{$formDisplay = $wk = " "; $formDisplay = ("<br><br><h2>Picks For this week are final!</h2> <br><br><br> Check Back Later To Make Your Picks For Next Week");} $result = mysql_query("SELECT * FROM users ORDER BY nc_points DESC"); while ($row = mysql_fetch_object($result)) { $leaderboard[] = $row->user_name; $leaderboardPoints[] = $row->cfb_points; } $result1 = mysql_query("SELECT CollegeFootballGames.ID, CollegeFootballGames.Week, CollegeFootballGames.Away, CollegeFootballGames.Home, CollegeFootballTeams.Team FROM CollegeFootballGames INNER JOIN CollegeFootballTeams ON CollegeFootballGames.Away = CollegeFootballTeams.ID || CollegeFootballGames.Home=CollegeFootballTeams.ID"); while ($row = mysql_fetch_object($result1)) { $GameID[] = $row->ID; $Teams[] = $row->Team; } ?> <? echo $formDisplay; ?> If you see what is wrong please tell me. it's supposed to check the file, to see if it's available for download, the code below looks okay to me, what's wrong? if($row[2]==2) // 4shared check { $row[1]="http://www.".$row[1]; $index=getpage($row[1]); preg_match("/Download ([^<]+)<\/div>/",$index,$match); if(strpos($index,"The file is shared for public access and download.")===false || !$match) { mysql_query("UPDATE `v2links` SET `checked`='-1',`lastcheck`=NOW() WHERE `id`=".$row[0]); print "bad link\n"; logstr("log-c.txt","bad link\n"); } else { $words=trim($match[1]); $words=preg_split("/[_\.\-\s]/",$words); $lastword=array_pop($words); $words=implode(" ",$words); $words=preg_replace("/\s{2,}/"," ",$words); $caption=mysql_real_escape_string($words); unset($words); unset($match); preg_match("/<td>Size\:<\/td><td>([^<]+)<\/td>/",$index,$match); $fsize=$match[1]; unset($match); print "$caption :: $fsize\n"; logstr("log-c.txt","$caption :: $fsize\n"); mysql_query("UPDATE `v2links` SET `checked`='1',`lastcheck`=NOW(),`fsize`='$fsize',`caption`='$caption' WHERE `id`=".$row[0]); if(mysql_errno()) print mysql_error()."\n"; } } I'm wondering if the sharing website has changed anything, because for rapidshare it works fine, code: if($row[2]==1) // rapidshare check { $index=getpage($row[1]); if(strpos($index,"<p><script>alert(\"File not found.\")</script>File not found.</p>")===false && strpos($index,"This file has been deleted.")===false) { preg_match("/<form action=\"([^\"]+)\" method=\"post\">/",$index,$match); //print $index; if($match[1]) { $fpath=$match[1]; $index=getpage($fpath,"dl.start=Free",$row[1]); preg_match("/<\/font> \(([^\(]+)\)\.<\/p>/",$index,$match); $fsize=0; if($match[1]) $fsize=mysql_real_escape_string(strip_tags($match[1])); print $fsize."\n"; logstr("log-c.txt",$fsize."\n"); mysql_query("UPDATE `v2links` SET `checked`='1',`fsize`='$fsize',`lastcheck`=NOW() WHERE `id`=".$row[0]); if(mysql_errno()) print mysql_error()."\n"; } else { print "bad link\n"; logstr("log-c.txt","bad link\n"); mysql_query("UPDATE `v2links` SET `checked`='-1',`lastcheck`=NOW() WHERE `id`=".$row[0]); if(mysql_errno()) print mysql_error()."\n"; } } else { print "bad link\n"; logstr("log-c.txt","bad link\n"); mysql_query("UPDATE `v2links` SET `checked`='-1',`lastcheck`=NOW() WHERE `id`=".$row[0]); if(mysql_errno()) print mysql_error()."\n"; } } any help would be appreciated! $result3 = mysql_query("SELECT User_ID FROM leaderboards WHERE User_ID = '$user'"); if(mysql_num_rows($result3) == 0){ $query1 = "INSERT INTO leaderboards (User_ID, CollegeFootballPoints) VALUES ('$user','$points')"; $result1 = mysql_query($query1); }else{ $query2 = "UPDATE leaderboards SET CollegeFootballPoints='$points' WHERE User_ID='$user'"; $result2 = mysql_query($query2); } I keep getting this error...' Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in update_collegeFBpoints_points.php on line 40 And the script is not working! (LINE 40 is $result3 = mysql_query("SELECT User_ID FROM leaderboards WHERE User_ID = '$user'"); if(mysql_num_rows($result3) == 0){ specifically mysql_num_rows) ok so before this.. if there isnt description for the company..the logo cant be click..only can be clicked if there is description added..im confused.. Code: [Select] <? if(isset($_GET[ttid])) { $ttid = $_GET[ttid]; } $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $query = "select master_event.* , (DATE_FORMAT(event_datefrom, '%d %M %Y')) as datefrom, (DATE_FORMAT(event_dateto, '%d %M %Y')) as dateto, ucase(event_name) as eventname from master_event where master_event.event_id = '$ttid '"; $result=mysql_query($query); while($row = mysql_fetch_array($result)){ $eventname = $row['eventname']; $eventdesc = $row['event_desc']; //$companydescription = $row['company_description']; $eventvenue = $row['event_venue']; $eventfee = $row['event_fee']; $datefrom = $row['datefrom']; $dateto = $row['dateto']; echo "<font color='#000000' face='arial' ><b> $eventname </b> </font> <br>"; echo "<font color='#000000' face='arial' ><i>Date</i> : $datefrom - $dateto <br>"; echo "<i>Venue</i> : $eventvenue <br>"; $querypstype = "SELECT DISTINCT master_pstype.pstype_id, pstype_desc FROM master_pstype INNER JOIN master_psevent ON master_psevent.pstype_id= master_pstype.pstype_id where master_psevent.event_id = '$ttid' ORDER BY pstype_order"; $resultpstype=mysql_query($querypstype); while($rowpstype = mysql_fetch_array($resultpstype)){ $pstypeid = $rowpstype['pstype_id']; $pstypedesc = $rowpstype['pstype_desc']; echo "<br><font color='#8B3A3A' size='1' face='georgia' ><b><i>$pstypedesc</i></b></font> <br>"; $queryps = "SELECT master_psevent.*, pstype_desc, company_name, company_link, company_description, logo_filename FROM master_psevent LEFT JOIN master_pstype ON master_psevent.pstype_id = master_pstype.pstype_id LEFT JOIN master_ps ON master_ps.ps_id = master_psevent.ps_id WHERE master_psevent.event_id = '$ttid' and master_pstype.pstype_id= '$pstypeid' ORDER BY pstype_desc,company_name "; $resultps=mysql_query($queryps); while($rowps = mysql_fetch_array($resultps)){ $companyname = $rowps['company_name']; $companyid = $rowps['ps_id']; $companylinkori = $rowps['company_link']; $companydescription = $rowps['company_description']; $logopath = $rowps['logo_filename']; $describelink = "index.php?ttid=$ttid&content=describe&pstypeid=$pstypeid&psid=$companyid"; echo "<a href=\"$describelink\" target=\"_blank\"><img src=".$logo_dir."/".$logopath." width=\"15%\"></a>"; ?> <br> <? } echo "<br>"; } } ?> im new..so to make it simple..the problem is ..i want it to be (if there is description = logo can be click, if no = otherwise) I did a big upgrade to my CMS and now the editing of an upload doesn't seem to work. The id is pulled from a list on the previous page and is functional. Here is the form: $id=$_GET['id']; $data = mysql_query("SELECT * FROM headerimg WHERE id = '$id'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { echo " <div id='edit'> <form method='post' action='headerimgeditprocess.php?id=".$id ."' enctype='multipart/form-data'> <fieldset> <legend>".$info['title'] ."</legend> <table> <tr><td colspan='2' style='text-align:center'><img src='../upload/headerimg/".$info['image'] ."' width='300'><br /><br /></tr></td> <td> Title:</td> <td> <input type='text' name='title' value='".$info['title'] ."'> </td></tr> <tr><td> Image: </td><td> <input type='file' name='image'></td></tr> </table> <br/> <br/> <input TYPE='submit' name='upload' title='Add data to the Database' value='Submit'/> </fieldset> </form> Here is the processor: $target = "/var/chroot/home/content/87/6409087/html/upload/headerimg/"; //This gets all the other information from the form $title=$_POST['title']; $id=$_GET['id']; if ($image != ''){ $image = ($_FILES['image']['name']); foreach($_FILES as $file) { move_uploaded_file($file['tmp_name'], $target . $file['name']); } mysql_query("UPDATE headerimg SET image ='$image' WHERE id ='$id'"); } //Writes the information to the database mysql_query("UPDATE headerimg SET title = '$title' WHERE id ='$id' "); ?> <p>Update Successful... <a href="../main.php">click here</a> to return to the administration area.</p> Hi all. I always create my sql queries like below. $user = "user"; $pass = "123456"; $host = "localhost"; $base = "test"; $cn = mysql_connect($host, $user, $pass) or trigger_error("SQL", E_USER_ERROR); mysql_select_db($base,$cn) or trigger_error("SQL", E_USER_ERROR); $QUERY = mysql_query("SELECT id FROM someTable", [size=14pt][color=red][b]$cn[/b][/color][/size]) or die(mysql_error()); while ($list = mysql_fetch_assoc($QUERY)){ echo "Some Text over loop"; } Okay here is the question (or problem). What if i have 5000 records in my Table. Doesn't this code connect DB 5000 times? If yes, then how can i optimize it? Hi guys (again), thanks a lot for your previous help. I'm trying to learn about conditional statements and I've tried to create a form to produce a echo statement when all the conditions are met. Below is my code, it is in two files... baconandeggs.php <html> <head></head> <body> <form action="baconandeggsform.php" method="post"> <!-- Question One --> <p>Please choose what day it is:</p> <select name="$day"> <option value="monday">Monday</option> <option value="tuesday">Tuesday</option> <option value="wednesday">Wednesday</option> <option value="thursday">Thursday</option> <option value="friday">Friday</option> <option value="saturday">Saturday</option> <option value="sunday">Sunday</option> </select> <br /> <!-- Question Two --> <p>Please enter the time:</p> <input type="$time" name="time"> <br /> <!-- Question Three --> <p>Please choose what country you are from...</p> <select name="$country"> <option value="uk">UK</option> <option value="usa">USA</option> <option value="europe">Europe</option> </select> <!-- Form Submit --> <input type="submit"> </form> </body> </html> baconandeggsform.php <html> <head></head> <body> <?php if ($day == 'thursday') { if ($time == '0800') { if ($country == 'uk') {$meal = 'bacon and eggs';} else {$meal = 'sausages';} } } ?> <?php echo $meal; ?> </body> </html> Any ideas why it isn't working? I've probably done something really obvious, but I have been trying to figure it out for a few hours now and it's doing my head in! I am trying to create a very basic object but am having troubles. Code: [Select] <?php class item{ public $name; public $price; function __construct($name,$price){ $this->name=$name; $this->price=$price;} function getName(){ return $this->name; } } $object = new item("car",400); echo $object->getName(); ?> The HTML output is: name=$name; $this->price=$price;} function getName(){ return $this->name; } } $object = new item("car",400); echo $object->getName(); ?> I'm sure that this code is clean but for some reason will not output the desired result! any help would be great. thanks. or should I say can you tell me WHAT is wrong? getting error on line 19 Parse error: syntax error, unexpected '[' in /home/heaven/public_html/tester/view_thread2.php on line 19 <?php include("connect.php"); mysql_select_db("heaven_forum") or die ("Could Not Select Database"); $recent = mysql_query("SELECT phpbb_posts.id AS post_id, phpbb_posts.topic_id AS topic_id, phpbb_posts.forum_id AS forum_id, phpbb_posts.poster_id AS poster_id, phpbb_topics.topic_title AS title, phpbb_users.username AS usernameFROM phpbb_posts, phpbb_topics ON phpbb_posts.topic_id=phpbb_topics.id, users ON phpbb_posts.poster_id=users.idORDER BY post_time DESC LIMIT 5"); //pull array $recent_row = mysql_fetch_assoc($recent); //set varibles pulled $topic_name = $recent ['title']; $poster = $recent['usernameFROM']; echo $topic_name; echo "Posted By: $poster"; ?> When the webpage loads it inserts all its information via xml into the database. This all works fine and perfect untill i reload the page again then it starts screwing up all the data im not sure what im doing wrong i know this isnt much info but is there a common mistake im making? Hey, did something happen with the Facebook login for the phpFreaks forum recently? Been trying to log in for some time now but I kept receiving errors. Glad it's back working now!
What an Earth is wrong with this code? Code: [Select] $query = "select sizes from products where id='$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); if ($row == 0) {echo "";} else {echo "Small - $row['sizes']";} PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING So this appears when I try and go on my index.php...
Warning: require_once(/TZ/v3/includes/db.php) [function.require-once]: failed to open stream: No such file or directory in /home/*REMOVED*/public_html/TZ/v3/index.php on line 5 Fatal error: require_once() [function.require]: Failed opening required '/TZ/v3/includes/db.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/*REMOVED*/public_html/TZ/v3/index.php on line 5It's saying there's no file there but there is! Thanks Edited by rizmah, 14 September 2014 - 08:20 AM. |