PHP - Help Putting Img Src Into A String For An Array Element Please
Hi, I have an array key whose value is a line of html in quotes, the problem is , I don't know how to do it. Lol. Any help greatly appreciated because the below code is generating an error in my editor. Thank you. Derek
here is the line. Code: [Select] 'level_1'=>"<img src='<img src='sundragon_environments/ocean/ocean1_FRAME.jpg'/>'", EDIT: actually I managed to fix the error adding a semicolon after the parenthesis. Is this array correct please? Code: [Select] $currentLocation = array ( 'teardrop_ocean_bg' => array ( 'level_1'=>"<img src='<img src='sundragon_environments/ocean/ocean1_FRAME.jpg'/>'" ) ); it's not finished yet. Similar TutorialsFolks, I am not able to find any function that will sort an array elements by its element's length. Does such function exist? Hello,
L.marker([{{$adLocation->lat}}, {{ $adLocation->lng }}]).addTo(locationMap) .bindPopup("<b>Add Location!</b><br />"+'{!! crlf($adLocation->content) !!}'+".").openPopup();
function crlf(string $s) : string { return str_replace( array("\r\n", "\r", "\n"), "<br />", $s); // 2 lines below does not work too // return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $s); // return nl2br($s); }
edit:539 Uncaught SyntaxError: Invalid or unexpected token
Hi guys, I've got quite a few fields in my tables that i've serialised to keep the number of fields down. For everything else that works perfect as it stores the data and when needed I can use the following as an example: $dateofbirth = unserialize($row['dateofbirth']); $dobday = $dateofbirth[0]; $dobmonth = $dateofbirth[1]; $dobyear = $dateofbirth[2]; Date of birth is stored as dd,mm,yyyy and for everything else I can call it fine. My issue is now that i'm trying to use fputcsv to create a csv file using the following: $result = mysqli_query($con, 'SELECT u.user_id, b.dateofbirth FROM Users u INNER JOIN Basic b USING (user_id) ORDER BY user_id DESC'); $fp = fopen('latest.csv', 'w'); fputcsv($fp, array('User ID', 'DOB' )); The CSV generates, but for the date of birth column in the csv it outputs as "a:3:{i:0;s:2:"03";i:1;s:2:"02";i:2;s:4:"1986";}" because it's obviously still serialised. What is my best and or easiest way of handling these fields? Many thanks in advance. Edited by Kristoff1875, 21 January 2015 - 05:24 AM. Thanks to the great help from some great people on this message board I'm right at the finish line on this page. I'm trying to mesh all the coding together at this point, and make it display the information. I keep getting 'mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource....etc..(filename/location) on line 51. Am I way off here??? Code: [Select] <?php $db_host = 'localhost'; $db_user = 'root'; $db_pass = ''; $db_in = new MySQLi ( $db_host, $db_user, $db_pass, 'sign_in' ); $db_out = new MySQLi( $db_host, $db_user, $db_pass, 'sign_out' ); if( $db_in->connect_error || $db_out->connect_error ) trigger_error( 'Unable to initiate database connections', E_USER_ERROR ); $q_in = 'SELECT * FROM `customer sign-in`'; $q_out = 'SELECT * FROM `customer sign-out`'; if( ($r_in = $db_in->query($q_in)) === FALSE || ($r_out = $db_out->query($q_out)) === FALSE ) trigger_error( 'Unable to grab ticket information from databases', E_USER_ERROR ); $data_in = array(); $data_out = array(); while( $row = $r_in->fetch_assoc() ) $data_in[ $row['Ticket #'] ] = $row; $r_in->free(); while( $row = $r_out->fetch_assoc() ) $data_out[ $row['Ticket #'] ] = $row; $r_out->free(); $result = array_diff_key( $data_in, $data_out ); echo "<table border='1'> <tr> <th>ID</th> <th>Sign In Date</th> <th>RANK/CIV</th> <th>First Name</th> <th>Last Name</th> <th>Unit</th> <th>DSN/Roshan</th> <th>Classifications</th> <th>Services Requested</th> <th>Service Tag/ Serial Number</th> <th>Ticket #</th> <th>Make/ Model</th> </tr>"; while($row = mysql_fetch_assoc($result)) { // Retrieve data until no more { echo "<tr>"; echo "<td>" . $row['ID'] . "</td>"; echo "<td>" . $row['Sign in Date'] . "</td>"; echo "<td>" . $row['Rank/CIV'] . "</td>"; echo "<td>" . $row['First Name'] . "</td>"; echo "<td>" . $row['Last Name'] . "</td>"; echo "<td>" . $row['Unit'] . "</td>"; echo "<td>" . $row['DSN/Roshan'] . "</td>"; echo "<td>" . $row['Classifications'] . "</td>"; echo "<td>" . $row['Services Requested'] . "</td>"; echo "<td>" . $row['Service Tag/ Serial Number'] . "</td>"; echo "<td>" . $row['Ticket #'] . "</td>"; echo "<td>" . $row['Make/ Model'] . "</td>"; echo "</tr>"; } } ?> Well, the title pretty much says it all. I'm trying to extract data from an array, put it into a 2D array and then sort it. Then I need to put it's "place" in the order into the table. I've sort of got something so far but it seems like my while loop isn't working correctly. $q="SELECT COUNT(*), horseID, total FROM enteredHorses"; $r = mysqli_query ($dbc, $q) or trigger_error(mysqli_error($dbc)); while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $count = $row['COUNT(*)']; $horse_id = $row['horseID']; $total = $row['total']; for ($counter = 1; $counter <= $count; $counter += 1) { $i = 0; $id[$i] = $horse_id; $total[$i] = $total; $i = $i+1; } } //end while array_multisort($total, SORT_DESC, $id); while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { for ($counter = 1; $counter <= $count; $counter += 1) { $i = 0; $place = '1'; $q = "INSERT INTO enteredHorses (place) VALUES ('$place') WHERE horse_id='$id[$i']'"; $r = mysqli_query ($dbc, $q) or trigger_error(mysqli_error($dbc)); $i = $i + 1; $place = $place + 1; } } I'm getting this error: "array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag " I'm really baffled. Any help? //First I'm assigning a $variable ($emailzipmatch) to query a database table called(repzipcodes) and having it pull and display 1 to 3 records based on matching up a customer's zip code (RepZipCode = $CustomerZipMatch) with 1 to 3 other people (GROUP BY RepId HAVING COUNT(1) <= 3") that want that customer's information from that particular zip code. <This code works fine> // CODE WORKS BELOW Code: [Select] <?php $emailzipmatch = mysql_query("SELECT * FROM repzipcodes WHERE RepZipCode = $CustomerZipMatch GROUP BY RepId HAVING COUNT(1) <= 3") or die(mysql_error()); $recipients = array(); while($row = mysql_fetch_array($emailzipmatch)) { $recipients[] = $row['RepEmail']; echo "Agent's Email Address: "; echo 'font color="#FF7600"',$row['RepEmail'], '/font'; echo '<br />'; echo "Rep's ID: "; echo '<br />'; echo 'font color="#FF7600"',$row['RepId'], '/font'; echo '<br />'; echo 'hr align="left" width="50%" size="2" /'; } //MY PROBLEM BELOW // For the NEXT step of the process above I would take $row['RepEmail'] and $row['RepId'] which can have 1 to 3 results and assign the 1 to 3 results a new $variable so it can be inserted into a different db table so I can track the results of the query ($emailzipmatch = ) from the top of the page: ie.. <New Variable> <Listed from above> $SentRepId 0 = RepId (results from above echo area) $SentRepId 1 = RepId (results from above echo area) $SentRepId 2 = RepId (results from above echo area) // Below I'd like to insert the above results into a new database $?Variable??? = mysql_query("INSERT INTO sentemail (SentRepId0, SentRepId1, SentRepId2,SentDateTime ) VALUES ( '$_SESSION[RepId]', // ????? '$_SESSION[RepId]', // ????? '$_SESSION[RepId]', // ????? NOW() )") or die(mysql_error()); Thank ahead of time for any help you guys can give me. Please respond with ANY question if my coding or request isn't clear or if I've been confusing due to my lack of experience with PHP and MySQL. MOD EDIT: code tags added. Hi Everyone, I have a problem displaying some information from an array (selected from my database). The array is below. Array ( [0] => Array ( [ssc_skill_categories] => Web [sc_skill_categories] => Programming ) [1] => Array ( [ssc_skill_categories] => Actionscript [sc_skill_categories] => Programming ) [2] => Array ( [ssc_skill_categories] => C# [sc_skill_categories] => Programming ) [3] => Array ( [ssc_skill_categories] => CSS [sc_skill_categories] => Programming ) [4] => Array ( [ssc_skill_categories] => Graphic [sc_skill_categories] => Designers ) [5] => Array ( [ssc_skill_categories] => Logo [sc_skill_categories] => Designers ) [6] => Array ( [ssc_skill_categories] => Illistration [sc_skill_categories] => Designers ) [7] => Array ( [ssc_skill_categories] => Animation [sc_skill_categories] => Designers ) ) What i would like to to is display this information in a table like so: <html> <body> <table> <tr> <td>Programming</td><td>Web</td><td>Actionscript</td><td>C#</td><td>CSS</td> <tr> <tr> <td>Designers</td><td>Graphic</td><td>Logo</td><td>Illistration</td><td>Animation</td> <tr> <table> </body> </html> I have been trying and failing all day to do this. Posting my "progress" will clog up the thread, so for now i wont post it. Does anyone have an idea how i would achieve this? Regards, -Ben Hi all! Ok I am trying to put a delimited list like so , EX. item qty, item name, item price | item qty, item name, item price | item qty, item name, item price | etc. into an array so I can access it like this - $product[0] = qty, $product[1] = name, etc. My code just isnt working. This is what I have so far. $prod = array(); //breaking products text down for display $products1 = explode("|", $products); $num_prod1 = count($products1); $count = 0; foreach($products1 as $p) { $prod[] = $p; $products2 = explode(",", $p); foreach($products2 as $p2) { $prod[$count] = $prod[$count][$p2]; } $count++; } Hi again all, Why does the foreach loop im doing, put the array values from collection, into seperate table rows rather than 1 row per whole array? <?php class registration{ public $fields = array("username", "email", "password"); public $data = array(); public $table = "users"; public $dateTime = ""; public $datePos = 0; public $dateEntryName = "date"; public $connection; function timeStamp(){ return($this->dateTime = date("Y-m-d H:i:s")); } function insertRow($collection){ //HERE foreach($this->fields as $row => $value){ mysql_query("INSERT INTO $this->table ($value) VALUES ('$collection[$row]')"); } mysql_close($this->connection->connectData); } function validateFields(){ $this->connection = new connection(); $this->connection->connect(); foreach($this->fields as $key => $value){ array_push($this->data, $_POST[$this->fields[$key]]); } $this->dateTime = $this->timeStamp(); array_unshift($this->data, $this->dateTime); array_unshift($this->fields, $this->dateEntryName); foreach($this->data as $value){ echo "$value"; } $this->insertRow($this->data); } } $registration = new registration(); $registration->validateFields(); ?> I end up with 3 rows row 1: username row 2: email row 3 : password rather than row 1:username email password. I'm creating a quick survey app for my son's cub scout pack's end-of-year surveys. There are two sets of questions: those where they want the responses to be completely anonymous and those questions where we need to know who filled out the response (people volunteering for positions, etc) I'm storing the responses in the db as two separate arrays, $anon and $nonAnon $anon[0] will be an array containing all the questions: $anon[0][0] = Survey question # 1 $anon[0][1] = Survey question #2, etc. The responses will be stored as arrays and placed in $anon as the 2nd element: $anon[1][0][0] = first response, answer to the first question $anon[1][0][1] = first resopnse, answer to the 2nd question $anon[1][1][0] = 2nd response, answer to the 1st question Etc. The pack leadership is concerned that no one would be able to reconstruct which anon response belonged to whom by matching up the order of the anon answers with the non-anon answers. Therefore I'd like to shuffle at least the anon responses. The long answer would be to build a temp array using the elements in $anon[1] and then shuffle that array and then reassign it to $anon[1]. Is there a way to use shuffle directly on $anon[1] without having to build a temporary array, shuffling it, then replacing the elements of $anon[1]? So I'm trying to create an Array from a comma separated string containing array{s}. How can I take a string full of comma separated hex values such as : <?php $myStr = ( "00ffff", "00cccc", "009999", "007777", "004444", "001111", "01ffff", "01cccc", "019999" ); ?> & turn it into 3 separated arrays like : <?php $myNewArrs = [ Array1 ( 3 ), Array2 ( 3 ), Array3 ( 3 ), ]; ?> which REALLY looks like : <?php $myNewArrs = [ Array ( "00ffff", "00cccc", "009999" ), Array ( "007777", "004444", "001111" ), Array ( "01ffff", "01cccc", "019999" ), ]; ?>
? Thank you & have a great afternoon!
Edited May 27 by AquariaXI Hi there! Ok I've a very simple code he $character = array (name=>"Joe", occupation=>"Programmer", age=>30, "Learned language "=>"Java" ); print_r($character); echo "<br/>"; foreach ( $character as $key=>$val ){ print "$key = $val <br>"; } The output is: Code: [Select] Array ( [name] => Joe [occupation] => Programmer [age] => 30 [Learned language ] => Java ) name = Joe occupation = Programmer age = 30 Learned language = Java Now instead of returning all the other elements, I just need to display only the first element in the array that is the value 'Joe'. I tried $val[name]; Output I get is not what I want: Code: [Select] J P J All responses/feedbacks is always welcomed Thank you! How would you access the number 10 in the $arr array? Hi, I have this array: $cats = array( "A"=>'Business Expansion Specialist', "B"=>'Affiliate Page', "C"=>'Personal: Hobbies', "D"=>'Personal: Pets', "E"=>'Personal: Holidays', "F"=>'Personal: Sport', "G"=>'Personal: C.V.', "H"=>'Personal: Other', "I"=>'For Sale: Antiques', "Z"=>'Other' );
And then from a table I get the variable $cat_cd. $cat_cd contains 'F' so it refers to 'Personal: Sport' If I want to put that in $category, how would I write that? I thought it might be .... $category = $cats['$cat_cd']; I tried that and it didn't work .
Thanks
Hi Everyone I am looking to just grab the first element of an array and do something to it but i only want this extra bit off code on the first value off the array. Here is my array echo "<pre>"; print_r($_SESSION); echo "</pre>"; Array ( [attach] => Array ( ) [backups-2] => true [dnb] => true [house] => true [tech-house] => true [uk-garage] => true [uk-grime] => true [uk-hip-hop] => true [uncategorized] => true [warehouse] => true [value] => Array ( [0] => Array ( [tune_name] => Music/dnb/Abort_Delta Heavy_192.mp3 [tune] => http://isdmusic.s3.amazonaws.com/Music/dnb/Abort_Delta Heavy_192.mp3 [submit] => Listen ) [1] => Array ( [tune_name] => Music/dnb/Acid Bath (Northern Lights remix)_Twisted Individual_192.mp3 [tune] => http://isdmusic.s3.amazonaws.com/Music/dnb/Acid Bath (Northern Lights remix)_Twisted Individual_192.mp3 [submit] => Listen ) [2] => Array ( [tune_name] => Music/dnb/Awkward_Inside Info_192.mp3 [tune] => http://isdmusic.s3.amazonaws.com/Music/dnb/Awkward_Inside Info_192.mp3 [submit] => Listen ) [3] => Array ( [tune_name] => Music/dnb/Awkward_Inside Info_192.mp3 [tune] => http://isdmusic.s3.amazonaws.com/Music/dnb/Awkward_Inside Info_192.mp3 [submit] => Listen ) ) ) so i just what to effect the first value what to and autostart to it??? Here is my code. session_start(); header("Content-type: text/xml"); $xml_output = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; $xml_output .= '<playlist version="1" xmlns="http://xspf.org/ns/0/">\n'; $xml_output .= "<trackList>\n"; $xml_output .= "\t<track>\n"; $xml_output .= "\t\t<location>" . $_SESSION['value'][0]['tune_name'] . "</location>\n"; $xml_output .= "\t\t<creator>sdf</creator>\n"; $xml_output .= "\t\t<album>sdf</album>\n"; $xml_output .= "\t\t<title>" . $_SESSION['value'][0]['tune_name'] . "</title>\n"; $xml_output .= "\t\t<annotation>I love this song</annotation>\n"; $xml_output .= "\t\t<duration>32000</duration>\n"; $xml_output .= "\t\t<image>covers/smetana.jpg</image>\n"; $xml_output .= "\t\t<info></info>\n"; $xml_output .= "\t\t<link>" . $furl . "</link>\n"; $xml_output .= "\t</track>\n"; foreach ($_SESSION['value'] as $value) { $furl = "http://isdmusic.s3.amazonaws.com/".urlencode($value['tune_name']); if(preg_match("/\.mp3$/i", $furl)) { $xml_output .= "\t<track>\n"; $xml_output .= "\t\t<location>" . $furl . "</location>\n"; $xml_output .= "\t\t<creator>" . $value['tune_name'] . "</creator>\n"; $xml_output .= "\t\t<album>" . $value['tune_name'] . "</album>\n"; $xml_output .= "\t\t<title>" . $value['tune_name'] . "</title>\n"; $xml_output .= "\t\t<annotation>I love this song</annotation>\n"; $xml_output .= "\t\t<duration>32000</duration>\n"; $xml_output .= "\t\t<image>covers/smetana.jpg</image>\n"; $xml_output .= "\t\t<info></info>\n"; $xml_output .= "\t\t<link>" . $furl . "</link>\n"; $xml_output .= "\t</track>\n"; } } $xml_output .= "</trackList>"; echo $xml_output; Thanks Given the following example code; if a function were passed the value of $id is there a way to point to the previous or next element in the array to retrieve their values. thanks Code: [Select] $arr = array(); for( $i = 0; $i < 10; $i++ ) { $id = mt_rand() + $i; $arr[$id] = "some value"; } function getValue( $id ) { $element = $arr[$id]; //point to previous element or next element beginning from $element position } I am trying to break down an array to make it easier to read. An array that looks like Array (
=> 0 [1] => 0 [2] => 0 [3] => 0012844 1 [4] => 37 [5] => 1 etc...) I want to display it like:
Code: [Select] [0] => 0 [1] => 0 [2] => 0 etc... how can this be accomplished. |