PHP - If Statement Not Displaying Right Part
Hi, i have written a section of code for my website and i have been trying to get it to work but whatever i try it will not work
Here is the code Code: [Select] $upgrade_user = mysql_query("SELECT * FROM user_info WHERE id='$id'"); while($row = mysql_fetch_array($upgrade_user)){ $real_balance = $row["$balance"]; $real_rank = $row["$rank"]; } echo $real_balance; if($real_rank == 'merchant' && $real_balance > '500'){ $n1x = '<a href="upgrades_info.php?userid=$id&rank=noble"><img src="images/noble.jpg" width="170" height="200" /></a>'; } else { $n1x = '<img src="images/noblex.jpg" width="170" height="200" />'; } It should outbut the first if, but instead it keeps displaying the else, i have checked the $real_rank and it matches merchant and the $real_balance is over 500. Any ideas? I am guessing its a simple error in the way i have written it, but i can't seem to get it to work. Thanks Similar TutorialsI am new to PHP and am currently learning the ropes. I have writen some code to insert a line into a mySQL database. I have created 3 fields in the mySQL database and am passing values two them. I can use a declared variable to pass information to the filed ID (Index filed in mySQL) but if I use a variable to pass purely text values the database is not updated. mysql_query( "INSERT INTO $tbl_name (category_Name, ID, test) VALUES ($category, $internalId, $category2)" ); If I replace the variables with specific text, the rows are added successfully. mysql_query( "INSERT INTO $tbl_name (category_Name, ID, test) VALUES ('werwerwer', $internalId, 'werrr')" ); It must be something stupid, I am sure. Full code below ob_start(); $host="localhost:8888"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="expenses"; // Database name $tbl_name="expense_category"; // Table name $category="test3"; $internalId="7"; $category2="test3"; // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_query( "INSERT INTO $tbl_name (category_Name, ID, test) VALUES ('werwerwer', $internalId, 'werrr')" ); echo "Done now 6!"; ?> Can someone show me the correct code to display a group of checkbox values as part of an if statement? For example: in Programme One, lesson 100, lesson 310 and lesson 102 are available. In Programme Two, lesson 302, lesson 201, and lesson 102 are available. The "lesson types" are a checkbox group. I need to output the lesson types depending on whether they are part of Programme One or Two, along with other variables such as instructor student ratio. I put the following code together where field_lessons is the checkbox group; <?php if ($fieldsObjects['field_type']->data == "Programme One") { print '<p class="details_heading03">Instructor Student Ratio</p>'; echo $fieldsFormatted['field_student_ratio']. '<br />'; foreach ($fieldsObjects['field_lessons']->data as $name => $value) { echo $value; echo "<br/>"; } else { echo "no"; } ?> I have also tried using this statement: <?php if ($fieldsObjects['field_type']->data == "Programme One") { print '<p class="details_heading03">Instructor Student Ratio</p>'; echo $fieldsFormatted['field_student_ratio']. '<br />'; echo (isset($fieldsObjects['field_lessons']->data) && is_array($fieldsObjects['field_lessons']->data)) ? } else { echo "no"; } ?> I am new to php, and I am customising a template which is part of Sobi2, which has been installed as a component of Joomla! (CMS)? Thank you jo Hey guys I'm having an issue trying to get my PHP to display the first url of my exploded string and non of the others.
The SQL table column contains strings like this:
http://www.imgurl.com/image.jpg,http://www.imgurl.com/image2.jpg,http://www.imgurl.com/image3.jpg,http://www.imgurl.com/image4.jpg Code: [Select] <?php $result = mysql_query("SELECT * FROM FamilyTbl INNER JOIN PeopleTbl ON (FamilyTbl.Name_ID = PeopleTbl.NameID) WHERE FamilyTbl.House_ID = '$address' ORDER BY NameLast, NameFirst ") OR die(mysql_error()); WHILE ($row = mysql_fetch_array($result) ) { echo $row[NameLast]. ", ". $row[NamePrefix]. " ". $row[NameFirst]. " ". $row[NameMiddle]. $row[NameSuffix]. " "; } ?> OK, some of these queries return A LOT of names. I'd like to be able to display them in columns in a table like so: Code: [Select] Charne, Mr. Michael Glanger, Mrs. Karin Kling, Mr. Wayne Charne, Mrs. Suzette Glanger, Mr. Trevor Lazarow, Mrs. Fiona Charney, Mrs. Linda Jochelson, Mrs. Barbara Lazarow, Mr. Mark Charney, Mr. Norman Jochelson, Mr. Neil Norton, Mr. Charles Cohen, Mr. Brendan Karlan, Mr. Dennis Norton, Mrs. Jodi Cohen, Mrs. Joanna Karlan, Mrs. Helen Roy, Mr. Michael Flekser, Mrs. Jean Kling, Mrs. Danielle Roy, Mrs. Nicki Frysh, Dr. Howard Kling, Mrs. Melanie Tsafrir, Mrs. Lauren Frysh, Mrs. Sandra Kling, Mr. Nevil Tsafrir, Mr. Thomer That way it reads top to bottom THEN left to right. math-wise, it's simple to set up: Code: [Select] $num_results = number_of_$results; $numcols = 3; $numrows = trunc($numresults/numcols); <table> for row_loop=1 to numrows <tr> for col_loop = 1 to numcols <td> echo result(col_loop-1)*(numrows)+row_loop </td> next col_loop </tr> next row_loop </table> Anyone want to give this a shot? Revraz already directed me to http://www.phpfreaks.com/forums/index.php/topic,95426.0.html but that displayed the data from left to right then up to down like so: Code: [Select] Charne, Mr. Michael Charne, Mrs. Suzette Charney, Mrs. Linda Charney, Mr. Norman Cohen, Mr. Brendan Cohen, Mrs. Joanna Flekser, Mrs. Jean Frysh, Dr. Howard Frysh, Mrs. Sandra Glanger, Mrs. Karin Glanger, Mr. Trevor Jochelson, Mrs. Barbara Jochelson, Mr. Neil Karlan, Mr. Dennis Karlan, Mrs. Helen Kling, Mrs. Danielle Kling, Mrs. Melanie Kling, Mr. Nevil Kling, Mr. Wayne Lazarow, Mrs. Fiona Lazarow, Mr. Mark Norton, Mr. Charles Norton, Mrs. Jodi Roy, Mr. Michael Roy, Mrs. Nicki Tsafrir, Mrs. Lauren Tsafrir, Mr. Thomer It's a good temp solution, but if anyone is good with for loops, I'd appreciate the help, thanks! -Dave Hi, Im a little confused on how to go about setting up a news section. i.e On my homepage i got it displaying Title: Postedby: brief: i would like a read more button... So it will go around index.php?news=$idfullstory (something like that) and on that page it will automatically show the full story etc.. Just a bit confused, so can someone break it down or even better point me in the right direction please? Thanks, J Hi, When i am getting the part of the text using the function substr, am getting this kind of problem , (text in the end not printing properly) how to solve this. تسر مؤسسة مهارات التقنية ومؤسسة اشبكة الثنائية ان تطلع جميع عملاءها بإصدار نظام تاتش لإدارة الموقع الالكترونية من يوم السبت ا� This is the code am using $sub_string_content = substr(strip_tags($temp['News_Content'],'<p></a><ul><li><div><span>'),0,300); Thanks, I am using the following php script to display all the files that are uploaded in a directory on a page. There are two files in the folder I do not want displayed: .htaccess & index.php. Can someone help me out and provide a little guidance about what I need to do to print all the file names EXCEPT for those two. I imagine some sort of if statement. CODE: Top of page: Code: [Select] <?php $dirname = "."; $dir = opendir($dirname); ?> Body: Code: [Select] <?php while(false != ($file = readdir($dir))) { if(($file != ".") and ($file != "..")) { echo("<a href='$dirname$file'>$file</a> <br />"); } } ?> Thanks so much! Here's the code, this is the PHP in my html contacts page (that IS in fact saved with a PHP extension): <div class = "centercontainer"> Code: [Select] <? $out = preg_replace('/^(.{701}[^.]*).*/i','$1.',$detrsltnewsrow[news_desc]); echo $out; ?> </td></tr><tr><td colspan="2" class="para" style="padding-left:10px;"> <?= substr(stripslashes(trim($detrsltnewsrow[news_desc])),701) ?> </td></tr> I have the above snippet.. The first php statement, basically grasp the first 701 characters with the closet next stop "." character and out puts it. then out puts the HTML tags I have a problem with the second statement. I want to output anything after what has been outputted by: Code: [Select] <? $out = preg_replace('/^(.{701}[^.]*).*/i','$1.',$detrsltnewsrow[news_desc]); echo $out; ?> So need the correct syntax for Code: [Select] <?= substr(stripslashes(trim($detrsltnewsrow[news_desc])),701) ?> Currently it breaks at exactly the 701 character, want it to continue from the sentence the first code ended in. My query gets the results and orders by one of the fields. Once I get the MySQL results I would like to find the first entry that has a letter as the first character of the same field that the list was ordered by, then split the results in to two parts and swap them. So that the results that have a letter at the start of the same sorted field are as the begining and the results that have the numbers as the start at the end of the array. But also so that the array works the same way as the original results string, so i can use say $results['mysqlfield'] I'm having issues with the following: Code: [Select] <?php session_start(); $_SESSION['username']=$_POST['username']; $_SESSION['password']=$_POST['password']; if($_SESSION['username']=="username" && $_SESSION['password']=="password"){ if($_GET['product']=="add"){ $content.=' <p><label>Product Name:</label> <input type="text" name="product_name" size="30" /> <label>Product Price:</label> <input type="text" name="product_price" size="5" /> </p> <p><label>Product Category:</label> <input type="text" name="product_category" size="30" /></p> <p><label>Product Link:</label> <input type="text" name="product_link" size="30" /></p> <p><label>Product Image:</label> <input type="text" name="product_image" size="30" /></p> <p><label>Product Tag:</label> <input type="text" name="product_tag" size="30" /></p> <p><label>Product Keywords:</label> <input type="text" name="keyword" size="30" /></p> <p><label>Product Features:</label><br /> <textarea name="product_features" rows="10" cols="60"></textarea> </p> <p><label>Product Pros:</label><br /> <textarea name="product_pros" rows="5" cols="30"></textarea> </p> <p><label>Product Cons:</label><br /> <textarea name="product_cons" rows="5" cols="30"></textarea> </p> <p><label>Product Description:</label><br /> <textarea name="product_description" rows="10" cols="60"></textarea> </p> <p><label>Product Notes:</label><br /> <textarea name="product_notes" rows="5" cols="30"></textarea> </p> '; $logout='<div><a href="./acp_admincp.php?log-out">Log-Out</a></div>'; } elseif($_GET['product']=="view"){ } else{ $content.=' <a href="./admincp.php?product=add">Add New Product</a> <br /> <a href="./admincp.php?product=view">View Products</a> '; } } elseif(isset($_GET['log-out'])){ session_start(); session_unset(); session_destroy(); header("Location: ./admincp.php"); } else{ $content=' <form action="./admincp.php" method="post"> <p><label>Username:</label> <input type="text" name="username" size="30" />'; $content.='</p> <p><label>Password:</label> <input type="password" name="password" /></p>'; $content.='<p><input type="submit" value="Submit" name="Submit" /></p> </form>'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <base href="http://ghosthuntersportal.com/" /> <title>Ghost Hunter's Portal - Admin Control Panel</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="verify-v1" content="" /> <meta name="keywords" content="ghost, hunters, hunter, ghosts, spirit, spirits, paranormal, investigation, investigator, investigators, k2, emf, meter, kii" /> <meta name="description" content="Ghost Hunters Potal. Parnormal research equipment store." /> <meta name="author" content="Andrew McCarrick" /> <meta name="robots" content="index, follow" <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <img src="./logo.png" alt="Ghost Hunter's Portal Admin Control Panel" /> <br /> <div style="color: #AA44AA; font-size: 26px; margin-top: -30px; margin-left: 125px;">Admin Control Panel</div> <?php echo $logout; echo $content; ?> </body> </html> I can log-in, and get to the page with the two links on it. However, once I click one of the links it falls back to the log-in page, and it ends up being a never ending loop. It's doing this: Log-In --> Page with links ---> Log-In page again Should be doing this: Log-In --> Page with links --> Add Product page or View Products page I can never get into the the actual sub page. Just to be clear, the address bar actually shows product=add or product=view, but it still shows the log-in page. Hello Everyone, I have to change the if statements to a switch statement, in this game. Can anyone help? Thanks. var checkKeyPressed = function (e) { // Press key A or key D to make dog run to the left or right // The running speed is specified by the step variable, 10 by default. // If you replace 10 with a larger integer, the dog will run faster. //press A, dog runs left if (e.keyCode == "65") { if (prex[0] > 5) { prex[0] = prex[0] - step; } } //press D, dog runs right if (e.keyCode == "68") { if (prex[0] < right) { prex[0] = prex[0] + step; } } }; I am having problems making it so that if I typed site.php?url=http://example.com it would auto get rid of the http://. Here's my code. $url="{$_GET['url']}"; str_replace('http://', '', $url); echo "<a href=\"http://$url\">$url</a>"; I am trying to build a news feed which shows the first 100 characters of news copy. I have it working to paste in the full text but am not sure how to insert only the first 100 characters. Code: [Select] <?php while($news_row=mysql_fetch_array($news)) { echo " <div class=\"news_box\"> <h3><a href=\"html/news.html\" rel=\"shadowbox; width=800; height=400;\">".$news_row['news_title']."</a> </h3> ".$news_row['news_copy']." </div>"; } ?> is this part of code correct ? Code: [Select] $query = mysql_query("select * from username WHERE username='$username'"); if(mysql_query($query) > 0) { die("Username already in use."); } else { Hi People. Thanks to everyone that helped me yesterday with my file that finally connected to the database. However, I have added a new field to my DB and now get further problems. Here is the error message I am getting after I added the "ppr" stuff to both files. Please could someone look at my code and tell me where I'm going wrong. 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 http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php include "config01.php"?> <form name = 'form1' method = 'post' action='config01.php'> <table width="700" border="1" cellspacing="5" cellpadding="5"> <caption> Submit Your Airfield Details </caption> <tr> <td width="100"> </td> <td width="200">Your Name</td> <td width="200"><input type='text' name='username' maxlength='30'></td> <td width="100"> </td> </tr> <tr> <td> </td> <td>Height Above MSL</td> <td><input type='text' name='height_above'maxlength= '30'></td> <td> </td> </tr> <tr> <td> </td> <td>Mb Difference</td> <td><input type='text' name='mb_diff'maxlength='40'></td> <td> </td> </tr> <tr> <td> </td> <td>Alternative Airfield</td> <td><input type='text' name='alternative' maxlength='30'></td> <td> </td> </tr> <tr> <td> </td> <td>PPR</td> <td><input type='radio' name='ppr' value="Y"/> Yes <input type='radio' name='ppr' value="N" /> No</td> <td> </td> </tr> <tr> <td><input type='submit' name='submit' value='post' /></td> <td> </td> <td> </td> <td> </td> </tr> </table> </form> </body> </html> Then the code from config01.php Code: [Select] <?php $host = 'localhost'; $usr = "VinnyG"; $password = 'thepassword'; $db_name = 'sitename'; $username = $_POST["username"]; $height_above = $_POST["height_above"]; $mb_diff = $_POST["mb_diff"]; $alternative = $_POST["alternative"]; $ppr = $_POST["ppr"]; //connect to database mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); /* $sql01 = "INSERT INTO users SET username = '$username',height_above = '$height_above', mb_diff = $mb_diff, alternative = $alternative"; $result=mysql_query($sql01); */ //mysql_query("INSERT INTO users VALUES ('$username','$height_above','$mb_diff','$alternative')"); //mysql_query("INSERT INTO users (username, height_above, mb_diff, alternative) VALUES ('$username', '$height_above', '$mb_diff', '$alternative'"); //$insert_query = "INSERT INTO users (username, height_above, mb_diff, alternative) VALUES ('$username', '$height_above', '$mb_diff', '$alternative')"; //$insert_action = mysql_query($insert_query) or die ('Error Dring Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query); //mysql_query("INSERT INTO users VALUES ('$username','$height_above','$mb_diff','$alternative')"); CHANGES FOLLOW THIS LINE . . $query = "INSERT INTO users (username, height_above, mb_diff, alternative, ppr) VALUES ('$username', '$height_above', '$mb_diff', '$alternative', '$ppr'"; if( !$result = mysql_query($query) ) { echo "<br>Query: $query<br>Produced error: " . mysql_error() .'<br>'; } else { echo "Query ran and inserted " . mysql_affected_rows() . "row(s)."; } ?> I only added the one thing and I've gone and broken it already. It was working last night too.. :-( Hello.
How would I print the following:
http://site.com/break?return=site2.com
So that I can set a button containing site2.com.
Example: <a href="site2.com"></a>
And so forth:
http://site.com/break?return=site3.com
Would print: <a href="site3.com"></a>
Hello, I am new to the php community Hi all, I have the following : Code: [Select] print_r($fqlResult); Which gives the following result : Code: [Select] Array ( [0] => Array ( [src_big] => http://a5.sphotos.ak.fbcdn.net/hphotos-ak-ash4/299117_2121699756933_1079004376_2442101_3103384_n.jpg ) ) I want to grab just the image url from it and store it in a seperate variable. Any ideas how I can do this plzzz ? Thanks in advance, Scott. |