PHP - How Do I Break This Variable Up, Into Unlimited Amounts?
Quote
#adf #234432 #fwerfw I have this as a result of a form that has been completed. It might be twice that, it might be much much more. But what I want to do is render it on a page inside Divs. So each one is in a kind of shaded box. The CSS side of it is easy, but how do I extract each one of these into a variable useful means to surround each one by <div>$variable</div>? I thought it might be "explode", but you appear to have to state the [3] number of the variable to show. In this case, it's totally random. We won't be using these as Variables to trigger anything else, it's purely "for display" purposes. Similar TutorialsHi guys,
Can someone help me with this if statement please. I'm trying to create two delivery amounts, so I'm trying to use an if statement instead of $delivery = "3.50";. All items should have a rate of £3.50 except item id 22 which should be 0.50p.
When I use this if statement below it just takes the price of £3.50 and ignores the else the part of the formula..
Thanks in advance.
$delivery = "3.50"; Working with authorize.net script that is included in my php. Trying to figure out how to use a variable beyond the 'case' I can do just about anything... inside the case... But I need to use the variable outside of there. Code: [Select] //several cases above case 5: $this->approval_code = $pstr_trimmed; break; // case 7 is the authorize.net transaction ID - This is the one I want to work with case 7: echo "Transaction ID: "; echo $pstr_trimmed; $trans_id_test = $pstr_trimmed; break; // but this below won't work. I can't use the variable anywhere outside of the case. echo "the new variable is now...".$trans_id_test; How can i make unlimited sub categories when i have this mysql fields: id, name, parent Code: [Select] $query = "SELECT * FROM cats"; $result = mysql_query($query); while ($var = mysql_fetch_array($result)) { echo $var['name']; // now i need here some code for sub cats, but sub cat in subcat :( } Can someone help me? I'm building a form using ajax that will allow users to add additional rows to their submissions. The problem however is getting PHP to recognize those variables. So that if the user submits 5 rows, it reads and creates a variable for all 5. I'm pretty sure that doing this will involve some form of while() processing and a total row count, but I'm unsure how to name the variables on the form end and how to receive those into PHP without the script erroring out. Suggestions? I was thinking something along the lines of naming each variable something like "number_title" or as an example "5_title." Then using a while function to pull the data from $_POST[$number.'_title']; or something similar, but I'm unsure if that method would even work. i have a form that has a price field, but if anything other than a decimal (0.00) a zero is entered into the database. There is the problem of people trying to add a dollar sign before their amount. What is the best way to validate a price amount to be entered into the database. The column in the database type is decimal(6,2). Any suggestions? Hey all, If I want to have a category which can have subcategories, which in turn can have its own subcategories or belong to the parent category, and the subcategories can have more than one parent categories, is the most effective way to design this is to create a categories table and categories_join table where the categories table has a foreign key categories_join_id linking it to the categories_join table and the categories_join table has a field called parent_id which associates with the primary key of the categories table, therefore allowing me to have multiple subcategories to one category: categories_join table id parent_id 1 2 1 3 categories table id categories_join_id 1 1 2 2 3 3 So from the example above, the first category has two parents, category 2 and category 3. As an alternative option, in this post: http://stackoverflow.com/questions/5384183/database-design-question-categories-subcategories The second answer down mentions to use recursive programming? But he doesn't give an example of what he means. Is he saying you have a function call itself passing it parameters as to what the parent should be: function getParent($category,$parents = array()){ } Thanks for response. Hi everyone ! I am stuck on a task which I'm sure has been achieved by several others in the past. I need to create a category table with unlimited / infinite levels (depths) of categories, sub-categories, sub-sub-categories, sub-sub-sub-categories and so on. I need to know how to show the category tree through PHP. An example would be great or even a link to another page where someone has laid out a step-by-step tutorial. Please help! Thank you very much! Kind Regards, Xeirus. echo '<div class="gamename">'.$values[0].'</div>'; echo '<div class="gameimage"><a href="'.$values[3].'"><img src="'.$values[1].'"></a></div>'; NOW i want 2nd echo under 1st echo. I tried every single <br> combination but no luck Also my 2nd question is: my image and link is a variable, it displays the image but there is something wrong with link. Variable is just like this www.mydomain.com\image\blabla.php but it shows link as==> www.mydomain.com\ instead of what i wrote above. I have a chain of methods, is there anyway to end the chain half way through if some particular event happens? Here is an example (not the best but still an example): Code: [Select] <?php $age = $class->post("age")->callback(funciton(){ global $class; if($class->string() < 18){ // end the execution of the chain, doesn't execute toInt() } })->toInt(); ?> I'm trying to figure out how I can break a string down if the strings length is longer then lets say 140 characters including white space. At first I was figuring maybe maybe I could do something with explode or implode after I get a get my strings length but the string in question has no static values to them that would let me break it apart or put it back together. Now In most cases I would use substr() to return my 140 characters, however I need to take 140+ and make an array of the extra so I can run a for each on it. I am using this for an SMS app I am helping develop. I know I can limit my the output to only 140, just based on the notion that a single SMS is capped at 140-160 on most carriers. Unfortunately for me thats not the case so I need to break this apart and I am stumped, anyone got any ideas? I was wondering if you guys could help me 'break' a function I've been working on. It converts a CSV-formatted string to a 2d array following RFC4180. Here's the function. /** * * Covert a multi-line CSV string into a 2d array. Follows RFC 4180, allows * "cells with ""escaped delimiters""" and multi-line enclosed cells * It assumes the CSV file is properly formatted, and doesn't check for errors * in CSV format. * @param string $str The CSV string * @param string $d The delimiter between values * @param string $e The enclosing character * @param bool $crlf Set to true if your CSV file should return carriage return * and line feed (CRLF should be returned according to RFC 4180 * @return array */ function csv_explode( $str, $d=',', $e='"', $crlf=TRUE ) { // Convert CRLF to LF, easier to work with in regex if( $crlf ) $str = str_replace("\r\n","\n",$str); // Get rid of trailing linebreaks that RFC4180 allows $str = trim($str); // Do the dirty work if ( preg_match_all( '/(?: '.$e.'((?:[^'.$e.']|'.$e.$e.')*+)'.$e.'(?:'.$d.'|\n|$) # match enclose, then match either non-enclose or double-enclose # zero to infinity times (possesive), then match another enclose, # followed by a comma, linebreak, or string end | ####### OR ####### ([^'.$d.'\n]*+)(?:['.$d.'\n]|$) # match anything thats not a comma or linebreak zero to infinity # times (possesive), then match either a comma or a linebreak or # string end )/x', $str, $ms, PREG_SET_ORDER ) === FALSE ) return FALSE; // Initialize vars, $r will hold our return data, $i will track which line we're on $r = array(); $i = 0; // Loop through results foreach( $ms as $m ) { // If the first group of matches is empty, the cell has no quotes if( empty($m[1]) ) // Put the CRLF back in if needed $r[$i][] = ($crlf == TRUE) ? str_replace("\n","\r\n",$m[2]) : $m[2]; else { // The cell was quoted, so we want to convert any "" back to " and // any LF back to CRLF, if needed $r[$i][] = ($crlf == TRUE) ? str_replace( array("\n",$e.$e), array("\r\n",$e), $m[1]) : str_replace($e.$e, $e, $m[1]); } // If the raw match doesn't have a delimiter, it must be the last in the // row, so we increment our line count. if( substr($m[0],-1) != $d ) $i++; } // An empty array will exist due to $ being a zero-length match, so remove it array_pop( $r ); return $r; } And to use it: $csv = 'this,will,"be ""separated""",by "commas,",,"should work with ""multiline,"", ",entries some,last,data,"test"'; print_r( csv_explode($csvn) ); or $csv_eurwin = "this;will;'be ''separated''';by\r\n"; $csv_eurwin .= "'semicolons;';;'should work with\r\n"; $csv_eurwin .= "''multiline;'';';entries\r\n"; $csv_eurwin .= "some;'last';data;'test'"; print_r( csv_explode($csv_eurwin, ';', '\'', TRUE) ); Thanks! Here's the actual spec if anyone cares Code: [Select] 1. Each record is located on a separate line, delimited by a line break (CRLF). For example: aaa,bbb,ccc CRLF zzz,yyy,xxx CRLF 2. The last record in the file may or may not have an ending line break. For example: aaa,bbb,ccc CRLF zzz,yyy,xxx 3. There maybe an optional header line appearing as the first line of the file with the same format as normal record lines. This header will contain names corresponding to the fields in the file and should contain the same number of fields as the records in the rest of the file (the presence or absence of the header line should be indicated via the optional "header" parameter of this MIME type). For example: field_name,field_name,field_name CRLF aaa,bbb,ccc CRLF zzz,yyy,xxx CRLF 4. Within the header and each record, there may be one or more fields, separated by commas. Each line should contain the same number of fields throughout the file. Spaces are considered part of a field and should not be ignored. The last field in the record must not be followed by a comma. For example: aaa,bbb,ccc 5. Each field may or may not be enclosed in double quotes (however some programs, such as Microsoft Excel, do not use double quotes at all). If fields are not enclosed with double quotes, then double quotes may not appear inside the fields. For example: "aaa","bbb","ccc" CRLF zzz,yyy,xxx 6. Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes. For example: "aaa","b CRLF bb","ccc" CRLF zzz,yyy,xxx 7. If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double quote. For example: "aaa","b""bb","ccc" why is it that when i saved it adds a break tag i dont understhand heres the code i cant find it its only when i save or remove a video and save it it has a break Code: [Select] <?php require "scripts/connect.php"; if($_POST['submitbtn']){ $video1 = mysql_real_escape_string(html_entity_decode($_POST['video1'])); $video2 = mysql_real_escape_string(html_entity_decode($_POST['video2'])); $video3 = mysql_real_escape_string(html_entity_decode($_POST['video3'])); $video4 = mysql_real_escape_string(html_entity_decode($_POST['video4'])); if($video1){ if($video2){ if($video3){ if($video4){ $query = mysql_query("UPDATE videos SET video1='$video1',video2='$video2',video3='$video3',video4='$video4'"); header("location: http://www.mywebsite.com/admin/editvideos"); }else $msg = "PLEASE FILL IN"; }else $msg = "PLEASE FILL IN"; }else $msg = "PLEASE FILL IN"; }else $msg = "PLEASE FILL IN"; } mysql_close(); ?> <?php include "header.php";?> <?php if($email){?> <?php include "inc/nav.php"; ?> <div id="righthomecontent"> <?php require "scripts/connect.php"; $query = mysql_query("SELECT * FROM videos"); $rows = mysql_fetch_assoc($query); $video1 = stripslashes($rows['video1']); $video2 = stripslashes($rows['video2']); $video3 = stripslashes($rows['video3']); $video4 = stripslashes($rows['video4']); mysql_close(); ?> <center>MUST USE THIS IN VIDEOS ?wmode=opaque"</center><br> <center>All videos are Width='220' and Height='240'</center><br> <form class="editvideoform" action="editvideos" method="post"> <table> <tr> <td></td> <td><?php echo $msg;?></td> </tr> <tr> <td>VIDEO 1</td> <td><textarea cols=25 rows=10 name="video1"><?php echo $video1;?></textarea></td> </tr> <tr> <td>VIDEO 2</td> <td><textarea cols=25 rows=10 name="video2"><?php echo $video2;?></textarea></td> </tr> <tr> <td>VIDEO 3</td> <td><textarea cols=25 rows=10 name="video3"><?php echo $video3;?></textarea></td> </tr> <tr> <td>VIDEO 4</td> <td><textarea cols=25 rows=10 name="video4"><?php echo $video4;?></textarea></td> </tr> <tr> <td></td> <td><input type="submit" name="submitbtn" value="SUBMIT" /></td> </tr> </table> </form> </div> <?php } else { echo "<center><h1>PLEASE LOGIN</h1></center>"; } ?> <?php include "footer.php";?> I want to have a line break between the lastname and the age. Please help. echo $line["firstname"].' '.$line["lastname"].' Age is'.$line["age"].'!'; How can i break down strings for example i have a simple search database for products where as a user searches a term this can be one, two three words and so on. I'm using a wildcard; but i want the best way to get the possible search so i would like to break down the string into separate words and then use that to search the database using wildcards is this possible? Thanks for reading. Hi all, I realised as users register themselves in the registration form, they wrote their comments and experience in the comment box which was provided Example (this is the content which they have written) 'Sentence 1 - Abccafsafsafafasdfafasfafs Sentence 2 - dasddsadsadsadsdaddsda' As you can see, between Sentence 1 and 2 there is a break (space). However when we store it in our database, and generate it out as a webpage, the break (space) is gone, and sentence 1 and 2 merged Example 'Abccafsafsafafasdfafasfafsdasddsadsadsadsdaddsda' My question is, how can we prevent 2 different sentences from merging? Thanks Below is my code and attached it what has been generated after we have posted it in webpage Code: [Select] cho '<div id="panel3">'; echo '<table>'; /***Tutor's Comments***/ echo'<div id="tutor_comments">'; echo '<br/><tr><td class="row_header">Tutor\'s Comments</td></tr>'; if (!empty($row2['tutor_comments'])) { echo '<tr><td>' . $row2['tutor_comments'] . '<br/><br/></td></tr>'; } /***Tutor's Commitments***/ echo '<tr><td class="row_header">Tutor\'s Commitment</td></tr>'; if (!empty($row2['tutor_commitment'])) { echo '<tr><td>' . $row2['tutor_commitment'] . '<br/><br/></td></tr>'; } /***Admin_comments***/ echo '<tr><td class="row_header">Admin\'s Comments</td></tr>'; if (!empty($row2['admin_comments'])) { echo '<tr><td>' . $row2['admin_comments'] . '<br/><br/></td></tr>'; } echo '</table>'; //End of Panel 3's table echo '</div>'; //End of tutor_comments DIV hi i have some troubles to create a new line break for this code: i already tried: Code: [Select] echo "<input type='radio' name='gropu1' value='$id'>$data \n "; // Code: [Select] echo "<input type='radio' name='gropu1' value='$id'>$data.\n "; // Code: [Select] echo "<input type='radio' name='gropu1' value='$id' >$data.'\n'"; what is the correct syntax for that? Code: [Select] $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field'].","; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j].", "; } $csv_output .= "\n"; } print $csv_output; I'm using the above to get a csv output in my browser, but it appears as a string of text eg a1,a2,a3,a4,b1,b2,b3,b4,... I'd like it to appear as a1,a2,a3,a4 b1,b2,b3,b4 c1,c2,c3,c4 Any ideas how? Good morning, I passed a bunch of HTML tags over a function that delete then, keeping just the text between. The problem is, after that all the tags were replaced by line breaks. Something like this before the function: <tr> <td> Text </tr> </td> After the function the 4 tags were correctly removed but instead i receive just the string "Text" I receive 2 line breaks, the "Text" and other 2 line breaks, like this: Text In HTML code this line breaks has no tags like <br> or <p> it's just blanck lines. I need to get just the text, how can I get rid of then? I tried this and also didn't work. $text = str_replace("/n", "", $text ); Thanks Danilo Jr. I think a switch break will help in this situation but I am definitely open to suggestions The problem I am have is that if there are 2 "Funner" or "Funnest" in the database then it displays duplicates in the in the column. I know that is what the code is telling it to do. If you look at the first row it should split them if there are 2 and display one in each column. In one time slot there is only allowed: - 1 Fun - 1 Funner or Funnest - 1 Funner or Funnest The case I am working with is there is 1 Fun and 2 Funners. The 2 Funners should split and display one in each "Funner/Funnest" column. There are planty of unique identifiers if someone has an idea for me. function taken($theType, $theTime){ $day_view = $_GET['date']; $DOP = explode("-", $_GET['date']); $topDOP = date("M", mktime(0, 0, 0, $DOP['1']))." ".$DOP['2'].", ".$DOP['0']; $dayDOP = date("l", mktime(0, 0, 0, $DOP[1], $DOP[2], $DOP[0])); connect(); $sql = "select * from party_times where dates = '$day_view' and paidID ='paid' and times = '$theTime'"; $result = mysql_query($sql) or die(mysql_error()); $day_count = mysql_num_rows($result); while($info = mysql_fetch_assoc($result)){ if($info['type'] == "$theType" && $info['times'] == "$theTime"){ $conID = "select DISTINCT confirmID from party_receipt where partyID = '".$info['partyID']."'"; $conqu = mysql_query($conID) or die(mysql_error()); while($con = mysql_fetch_assoc($conqu)){ $cid = $con['confirmID']; echo "<a href='party_booked.php?view=$cid'>RESERVED</a>"; }free($conqu); } }free($result); } Call the function: Code: [Select] <tr> <td width="25%"></td> <td width="25%" align="center">Fun</td> <td width="25%" align="center">Funner / Funnest</td> <td width="25%" align="center">Funner / Funnest</td> </tr> <tr> <td>11:00 AM</td> <td class = "res"><?php taken("Fun", "11:00 AM"); ?></td> <td class = "res"><?php taken("Funner", "11:00 AM"); ?></td> <td class = "res"><?php taken("Funnest", "11:00 AM"); ?></td> </tr> Thank you! I'm pretty new to php (as in I suck at it) so please bear with me. I have an entire site within a frame so that the domain name always shows up, without anything after it. Within the site I have a page using the "winxp progress bar" javascript that pops up a java notification and then redirects to another page when the user clicks the "OK" button - when this happens, I'd like to break the frame so that the full URL of the new page is displayed. In HTML this would be target="_top" but I'm not sure how to do it here. Here is the code for the entire page: Code: [Select] <html> <head> <title>Searching</title> <script language="javascript" src="xp_progress.js"> /*********************************************** * WinXP Progress Bar- By Brian Gosselin- http://www.scriptasylum.com/ * Script featured on Dynamic Drive- http://www.dynamicdrive.com * Please keep this notice intact ***********************************************/ </script> </head> <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red"> <table border="0" width="804" align="center"> <tr> <td width="794" align="center"> <h2 align="center"><font face="Verdana">Searching for <?php echo $_GET['id'];?> ...</font></h2> <p align="center"> <script type="text/javascript"> function redirectpage(){ bar3.togglePause() alert('<?php echo $_GET['id'];?> Found!'); window.location="lp.php" } var bar3= createBar(400,15,'white',1,'black','green',125,7,2,"redirectpage()"); </script> </p> </td> </tr> </table> </body> </html> "lp.php" is the final page and the one that should break the frame. I'm not sure whether this should be done inside the redirect on this page, or if it should be done inside lp.php. lp.php is just another redirect (there used to be some more things on it but I took them all out and had too many links pointing to it to bother changing them all). This is the entire contents of lp.php: Code: [Select] <?php header("Location: http://www.[urlremoved].com"); ?> I'm assuming it would be easier to put the frame break on this page, but I really have no idea. If someone can help me with it I'd really appreciate it. |