PHP - Displaying Only The First Part Of An Exploded Php String
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 Similar TutorialsHi, 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 I'm using PHP to get a list of names from a mysql database, which then produces a drop down list for the user to select an option and then progress to the next page where the selection is displayed with other stuff. My problem is that my drop down list works fine, but when the user goes to the next page only the first part of the string is displayed, ie if the string is Fred Bloggs, only Fred is shown. I can get it to work by adding ' ' around the string name in the option section, but this shows 'Fred Bloggs' in the drop down list which isn't very pretty. I haven't got the actual code to hand at the moment, but any ideas on where I'm going wrong? Cheers 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 Let's say I have a variable called $big_paragraph I want to display the variable IF it contains the word "hello". The word may or may not be there AND it could be anywhere in that paragraph (separated by a space before and after it to signify that it is a word). So I can't use substr since it assumes I know the position. Thanks. I have string like this (without the spaces) [ QUOTE="Adrock"]This is a test message[/QUOTE ] How do i get just what is between the double quotes taking into account in the message there could be double quotes? I've tried this but it doesn't echo anything unless i put the square brackets in but i want the username $origauth = html_entity_decode($message); $b = substr($origauth, strpos($origauth, '&#034') + 1); $c = substr($b, 0, strpos($b, '&#034')); echo $c; hi php freaks, have link in a menu that looks like the following. I have been able search the string using strpos($lines[$i],'title='). What I want to know is how do I get the school summary into a variable. Code: [Select] <li><a href="../index.php" title="school summary">Summary</a></li> any help would be great Hi i need help with some string manipulation and extraction.. http://www.test.com/forums/attachment/f39/745d1267084199-official-ar-m16-m4-picture-thread-dsc00005.jpg I need to extract an id from the above path dynamically. I need to extract the digits before the alphabet d after the second last path f39/ In the above case the number extracted would be 745. Can someone please help me out with it? Hello guys, I want to remove part of a string and convert it to a var instead of echoing it out.. How would I do it.. $string = "temp_photo/testing.jpg"; I want to remove temp_photo so the out put should be $filename2 = testing.jpg Please advise.. Thanks, Dan Hi - newbie to php - I need to search a string and possibly replace part of it. This is how I would do it in perl: Code: [Select] if ($homepage) { if ($homepage !~ /http/i) { $homepage = "http:\/\/" . $homepage; } } I have a homepage field in the database but sometimes people put the http in, and sometimes they leave it out. In perl I can figure it out and format accordingly but it doesn't work in PHP. I'm not sure if the first line even works in PHP. Maybe if to say something like: if $homepage is not equal to nothing. I'm not sure. Any help would be appreciated. Thanks. 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, Hey there. Thinking this should be an easy one but I can only seem to find info on the string replace function. What I'm trying to do is strip everything after the @ from an email variable. So for example $mail variable comes in as me@gmail.com How would I strip the variable to only contain me and remove the @gmail.com I'll keep searching for the answer myself but if anyone can throw me a bone it's be appreciated. Cheers I have the following DOM document ( this is a sample document and is "as is", it's 100% intended to look like this ): <everything> <cars> <car>ladia</car> <car>ferrari</car> <garage>big blue building</garage> i also have a McLaren F1 but i wont brag about it </cars> <houses> <house>Big Red House</house> </houses> </everything> This is all being put into a $newdoc = new DOMDocument(); $myString = ................. ; // ????? I only want the content of <cars> in here, and without having the <cars> tag How can I make this "$myString look like the following: $myString = ' <car>ladia</car> <car>ferrari</car> <garage>big blue building</garage> i also have a McLaren F1 but i wont brag about it '; Preferably without any looping. Hey guys! I found a flush function and it seems to be working well, but sometimes it will cut off characters. It's very strange. Here's my flush function: function out($str) { echo $str."<br />\n"; vbflush(); } function vbflush() { if (ob_get_length()){ @ob_flush(); @flush(); @ob_end_flush(); } @ob_start(); }And I'm calling it like this:out('Waiting 30 seconds until execution');And this is my output: Code: [Select] Waiting 30 seconds until executioAnyone know why? Hi all, first time here as I am a bit stuck. I am by no means a programmer and I was hoping that someone out there may have a simple solution to my problem?... So here goes" I have a voucher/offers site up-and-running. The site content is generated from an external feed. I want to create other sites and I want to track what sales/clicks have come from where. An example of the feed: (http://www.awin1.com/awclick.php?mid=251&id=28971&clickref=[URL_REFERENCE]&p=http://www.247electrical.co.uk) As you will see, I have [URL_REFERENCE] in each link. I want to automatically change that part of the string in the database. Does anyone have any thoughts? Hello, I have several job categories on a recruitment website: $job_category[0]="accountant"; $job_category[1]="php programming"; $job_category[2]="baseball"; these job categories are contained within the urls imediately after the recruiting company's name and before the word "jobs", so we could have the following urls: www.url.com/company_name_accountant_jobs www.url.com/another_company_name_baseball_jobs www.url.com/yet_another_company_name_php programming_jobs Using the array $job_categories and the page path after the foward slash (e.g. yet_another_company_name_php programming_jobs) please could you tell me how to strip out the job category and the company name? (I'll extract the page path using a mod_rewrite) Thanks Stu Is there a way to send exploded data into a database without using multiple loops just to do so? My current code, but it only inserts the name value in the database as Array. $chicken_names = mysql_real_escape_string($_POST['names']); $chicken_names_exp = explode(' ', $_POST['names']); foreach($chicken_names_exp as $value) { mysql_query("INSERT INTO names VALUES (null, '$chicken_names_exp"', '". $_POST['type'] ."')"); } echo "Success! You have successfully sent in your chicken names! <a href='index.php'>Home</a>"; Code: [Select] $teamLineUp=explode(";", $team['lineUp']); #This is the team line up foreach ($teamLineUp as $value) echo "<BR>".$value; this works fine and outputs what I want EXCEPT if a word has a ' in it; for example the name O'Reilly gets broken into 2 values "O" and "Reilly"; is there a way around this? apparently I am doing this wrong. I want my string results from a form that searches DB content to appear within HTML table, tr, td tags. I get the results fine, but the HTML part isn't appearing. How should I be doing this? <?php $string = ''; $result = mysql_query($sql); /// This is the execution if (mysql_num_rows($result) > 0){ while($row = mysql_fetch_object($result)){ echo "<table>"; echo "<tr>"; $string .= "<td>".$row->last_name."</td> "; $string .= "<td>".$row->first_name."</td>"; $string .= "<td>".$row->employee_id."</td>"; $string .= "<td>".$row->title."</b>"; $string .= "<td>".$row->territory."</td>"; $string .= "<td>".$row->district."</td>"; $string .= "<td>".$row->Phase1A_Score."</td>"; $string .= "<td>".$row->Phase1B_Score."</td>"; $string .= "<td>".$row->Phase1_Average."</td>"; $string .= "<td>".$row->Phase1A_HS_Exam."</td>"; $string .= "<td>".$row->Phase1A_HS_Exam_RT."</td>"; $string .= "<td>".$row->Phase1B_HS_Exam."</td>"; $string .= "<td>".$row->Phase1B_HS_Exam_RT."</td>"; $string .= "<td>".$row->Class_Date."</td>"; $string .= "<td>".$row->Awards."</td>"; $string .= "<br/>\n"; echo "</tr>"; echo "</table>"; } }else{ $string = "No matches found!"; } echo $string; ?> This is what I have now...im getting an undefined offset error, but $i should be set....unless my loop is a fail? I don't know... <form action="<?php echo $_SERVER['PHP_SELF']; ?>"method="post"> <label>URLs delimited by a COMMA</label> <textarea name="urls"></textarea> <input name="submit" type="submit" value="Submit" /> </form> <?php if (isset($_POST['submit'])) { $urls = trim($_POST['urls']); // remove white space from user input $arr = explode( ",", $urls); // convert the input into an array $count = count($arr); // count the number of items in the array for ($i = 0; $i <= $count; $i++) { // setup the loop to stop iteration when $count is met echo '<pre><a href="' . $arr[$i] . '>' . $arr[$i] . '</a></pre>'; // Hopefully echo the link list back if all goes well... } } ?> |