PHP - Get Arrays And Checkbox Checked When Returning Url
Hello,
Hope someone can help me cause i been at it all day and google woul'dn't help me. I been writing a little script which generates a list of numbers you can check and make a list of the numbers that have been checked. Now when i use $_get to the next page everything works but now i need to take the url and use $_get back to the generated check box list and it needs to know by the url which box had been checked and checked that one so the list can be altered. here is my code sofar 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>AH plaatjes.</title> </head> <body name="top"> Meer info beneden aan de pagina. <a href="#beneden">Naar beneden.</a> <p> <script language=JavaScript> function set(n) { temp = document.form1.elements.length ; for (i=0; i < temp; i++) { document.form1.elements[i].checked=n; } } function checkall() { void(d=document); void(el=d.getElementsByName('check')); for(i=0;i<el.length;i++) void(el[i].checked=1) } //invert function invers(){ temp = document.form1.elements.length ; for (i=0; i < temp; i++){ if(document.form1.elements[i].checked == 1){document.form1.elements[i].checked = 0;} else {document.form1.elements[i].checked = 1} } } </script> </p> <form id="form1" name="form1" method="get" action="./readlist.php"> <label>Naam eigenaar lijstje:<input name="naam" type="text" /></label> <label>Lijst van selectie plaatjes<select name="collect"> <option value="0">selecteer optie!</option> <option value="1">in decollectie</option> <option value="2">nog niet in collectie</option> <option value="3">dubbele collectie</option> </select></label> <p> <?php //TO Do trying to get the checkboxes checked with get and array ///////////////// do { $i = $i+1; echo " <input type=\"checkbox\" name=\"checked[]\" id=\"check\" value=\"". $i ."\"/> <label for=\"". $i ."\">". $i ."</label> <br /> "; if($i > 324){break;} }// end do while($i < 325); ?> </p><input name="check" type="submit" value="Print lijst" /> <input type=button onClick="checkall()" value="selecteer alles" name="button"> <input name=button onclick="invers()" type=button value=" Keer selectie om "> <INPUT name=button onclick=set(0) type=button value=" Reset "> </form> <p><a name="beneden">De geselecteerde nummers komen overzichtelijk in een lijstje. Zo heb je heel overzichtelijk een lijst met de nummers die je al hebt of juist nog niet hebt. Die kan je dan doorsturen selecteren en kopieren met je rechtermuis knop en naar je kennissen of vrienden sturen.</a> ook kan je de url (webadres) kopieren en doorgeven.</p> <p><a href="#top">Naar boven.</a></p> </body> </html> Now what i need is when you fill out an url like http://localhost/ah/index.php?checked%5B%5D=2&checked%5B%5D=3 it needs to check the same boxes. please help me out thanks in advance Similar TutorialsI am using the following piece of code to open a new window when a checkbox is checked... <INPUT type="checkbox" name="name" value="YES" onClick="window.open('/somepage.php?do=something&id=<?php echo $SOMEID["id"] ?>','','width=600,height=350,left=100,top=100,screenX=100,screenY=100')"> The page opens ok when the checkbox is ticked (checked). PROBLEM: The page opens again if the checkbox is un-ticked (un-checked). I just want to open the page if the checkbox is ticked only but not sure how to do this? OTHER INFO: Seperate checkboxes are dynamically created on the page for each id=<?php echo $SOMEID["id"] ?> What is the best way using php to see if a checkbox is checked or not. I see so many different options out there googling, that I am interested knowing the most robust method. Thanks Hi: How do I check to see if a checkbox has not been checked? Would the same rules apply to a radiobutton? This is what I have: Code: [Select] <input name="status[1]" id="approved" value="<?php echo $_POST['approved'] ?>" type="checkbox" /> <label for="approved">Approved</label> Code: [Select] if (isset($_POST['status[1]'])): $errMsg['status[1]'] = "Must select a status."; endif; I tested it out, but it just prints the error message even if I have checked it hi all I have 3 checkboxes whose values are getting stored in the database with a comma separator. Code: [Select] <input name="color[]" type="checkbox" value="red" id="red" />red <input name="color[]" type="checkbox" value="blue" id="blue" />blue <input name="color[]" type="checkbox" value="green" id="green" />green values getting stored with comma separator Code: [Select] red, blue, green now i want to show the checkboxes as "checked" to show the customer as which colors they chose lasttime when they submitted the form. How can i make it possible ? If it is possible without the comma separator then i can remove the comma. vineet This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=349419.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=349419.0 Hi all, I have been trying to figure this out for a few days already and can't seem to figure it out. I want to display a few images with a checkbox next to it so I can delete multiple images at once when I press the delete button. My problem is that I can't seem to figure out how to check if the checkbox is checked. if I uncheck one of them and click the delete button it deletes one from the array but I don't know which one was unchecked. For example if I uncheck the second one the array shows: Array ( => on [1] => on ) but I don't know which of the three was unchecked? Here is the code I have been testing with: Code: [Select] <?php // if submit button is clicked if(isset($_POST['submit'])) { // do delete function(); } // display deletethis[] array if (isset($_POST['deletethis'])) { echo "<pre>"; print_r ($_POST['deletethis']); echo "</pre>"; } $separate = array("http://funnypicturesimages.com/images/image/funny-dog-pictures.jpg", "http://1.bp.blogspot.com/-35wQMpYtNZc/TXWNx8y2xCI/AAAAAAAB_2o/9vZYNfWrGn8/s400/funny_demotivational_posters_01.jpg", "http://3.bp.blogspot.com/-TFnzZ8zFtgg/TXWNpodBkGI/AAAAAAAB_2Q/O_fOOSqFM6w/s400/funny_demotivational_posters_04.jpg"); echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">'; // display each image from array foreach ($separate as $value) { echo "<img src=".$value.">"; if ($_POST['deletethis'] = "on") { $checked="checked"; } else { $checked=""; } if ($_POST['deletethis'] != "") { echo "checked"; } else{ echo "unchecked"; } // if checkbox currently checked display it checked else display unchecked if ($checked == "checked") { echo '<input type="checkbox" name="deletethis[]" checked="checked"/><br /><br />'; } else { echo '<input type="checkbox" name="deletethis[]"/><br /><br />'; } } ?> <center><input type="submit" name="submit" value="Delete Checked"></center> </form> I'm trying to create a series of functions, when activated: a. scans a target directory for jpg's -> returns file names to an array b. takes those file names and stripes the .jpg from them -> return file name, extension, and full filename c. inserts said file names into a MySQL database Here's the problem: The second function won't loop on the return array('name' => $name), it just does it once. Code: Function 1 (of 3) Code: [Select] function scanJpg($phpath){ $dir = opendir($phpath); while(false !== ($file = readdir($dir))){ if($file != "." && $file != ".."){ if(!is_dir($phpath.$file)){ $results[] = $file; } } } closedir($dir); return $results; } // returns // Array ( [0] => lakeonrefuge.jpg [1] => shasta04.jpg [2] => carly_lol.jpg [3] => beach_adventures_florence.jpg [4] => beach_adventures.jpg [5] => Beach-0168.jpg ) function 2 Code: [Select] function stripJpg($jpgs,$phpath){ foreach($jpgs as $jpg){ $ext = strrchr($jpg, '.'); if($ext !== false) { $name = substr($jpg, 0, -strlen($ext)); echo $name."<br />"; echo $jpg."<br />"; echo $ext."<br /><br />"; return array( 'name' => $name, 'filename' => $jpg, 'ext' => $ext ); } } } ## $jpgs = scanJpg($phpath); ## print_r(stripJpg($jpgs,$phpath)); ## ## returns the following ## Array ( [name] => lakeonrefuge [filename] => lakeonrefuge.jpg [ext] => .jpg ) What am I overlooking? Thanks in advance! Hey guys, how do I send checkbox variables to my e-mail address once a user has checked it on the html form. Here is my html form: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Form</title> <script type="text/javascript"> //email form validation function everif(str) { var at="@" var punct="." var lat=str.indexOf(at) var lstr=str.length var lpunct=str.indexOf(punct) if (str.indexOf(at)==-1){ alert("Valid email must be entered") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ alert("Valid email must be entered") return false } if (str.indexOf(punct)==-1 || str.indexOf(punct)==0 || str.indexOf(punct)==lstr){ alert("Valid email must be entered") return false } if (str.indexOf(at,(lat+1))!=-1){ alert("Valid email must be entered") return false } if (str.substring(lat-1,lat)==punct || str.substring(lat+1,lat+2)==punct){ alert("Valid email must be entered") return false } if (str.indexOf(punct,(lat+2))==-1){ alert("Valid email must be entered") return false } if (str.indexOf(" ")!=-1){ alert("Valid email must be entered") return false } return true } function evalid(){ var emailID=document.contact_form.mail if (everif(emailID.value)==false){ emailID.focus() return false } //empty field validation var naam=document.contact_form.naam if ((naam.value==null)||(naam.value=="")){ alert("Fields marqued with * must be entered") naam.focus() return false } var telefoon=document.contact_form.telefoon if ((telefoon.value==null)||(telefoon.value=="")){ alert("Fields marqued with * must be entered") telefoon.focus() return false } var branche=document.contact_form.branche if ((branche.value==null)||(branche.value=="")){ alert("Fields marqued with * must be entered") branche.focus() return false } return true } </script> </head> <body> <form name="contact_form" method="post" id="contactform" action="doeactie.php" onSubmit="return evalid()"> <table border="0"> <tr> <td><label for="bedrijfsnaam">Company name</label></td> <td colspan="2"><input name="bedrijfsnaam" type="text" class="text" size="30" /></td> </tr><tr> <td><label for="naam">Name *</label></td> <td colspan="2"><input name="naam" type="text" class="text" size="30" /></td> </tr><tr> <td><label for="mail">E-mail *</label></td> <td colspan="2"><input type="text" name="mail" class="text" size="30" /></td> </tr><tr> <td><label for="adres">Address</label></td> <td colspan="2"><input name="adres" type="text" class="text" size="30" /></td> </tr><tr> <td><label for="plaatsnaam">City</label></td> <td colspan="2"><input name="plaatsnaam" type="text" class="text" size="30" /></td> </tr><tr> <td><label for="postcode">Zip</label></td> <td colspan="2"><input type="text" name="postcode" class="text" size="10" /></td> </tr><tr> <td><label for="branche">Niche *</label></td> <td colspan="2"><input name="branche" type="text" class="text" size="30" /></td> </tr><tr> <td><label for="telefoon">Phone *</label></td> <td colspan="2"><input name="telefoon" class="text" type="text" size="30" /></td> </tr><tr> <td><label for="bericht">Question or Comment</label></td> <td colspan="2"><textarea name="message" class="text" onkeyup="return limitarelungime(this, 255)" cols="35" rows="5"></textarea></td> </tr> </table> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td></td> <td height="25"></td> </tr> <tr> <td></td> <td height="30" valign="top"><font face="arial" size="2"><b>I would also like to receive information about :</b></font></td> </tr> <tr> <td><input type="checkbox" name="emailmarketing" id="emailmarketing" value="emailmarketing" /></td> <td height="25"><font face="arial" size="2">E-mail Campaign</font></td> </tr> <tr> <td><input type="checkbox" name="zoekmachopt" id="zoekmachopt" value="zoekmachopt" /></td> <td height="25"><font face="arial" size="2">SEO</font></td> </tr> <tr> <td><input type="checkbox" name="socialmedia" id="id" value="socialmedia" /></td> <td height="25"><font face="arial" size="2">Social Media</font></td> </tr> <tr> <td><input type="checkbox" name="videomarketing" id="videomarketing" value="videomarketing" /></td> <td height="25"><font face="arial" size="2">Video Marketing</font></td> </tr> <tr> <td><input type="checkbox" name="webshop" id="webshop" value="webshop" /></td> <td height="25"><font face="arial" size="2">Webshop</font></td> </tr> <tr> <td><input type="checkbox" name="cms" id="cms" value="cms" /></td> <td height="25"><font face="arial" size="2">Content Management System</font></td> </tr> <tr> <td><input type="checkbox" name="grafisch" id="grafisch" value="grafisch" /></td> <td height="25"><font face="arial" size="2">Graphic Design</font></td> </tr> <tr> <td></td> <td align="left"><br /><input type="submit" name="Submit" value="Send"></td> <td align="right"></td> </tr> </table> </form> </body> </html> and this is the PHP script that processes this. Everything works except for the checkbox part. <?php session_start(); if(isset($_POST['Submit'])) { $youremail = 'blabla@gmail.com'; $fromsubject = 'Request from form'; $bedrijfsnaam = $_POST['bedrijfsnaam']; $naam = $_POST['naam']; $mail = $_POST['mail']; $adres = $_POST['adres']; $plaatsnaam = $_POST['plaatsnaam']; $postcode = $_POST['postcode']; $branche = $_POST['branche']; $telefoon = $_POST['telefoon']; $message = $_POST['message']; $to = $youremail; $mailsubject = 'Bericht ontvangen van'.$fromsubject.' Actie Pagina'; $body = $fromsubject.' Bedrijfsnaam: '.$bedrijfsnaam.' Naam Contact Persoon: '.$naam.' E-mail: '.$mail.' Adres: '.$adres.' Plaatsnaam: '.$plaatsnaam.' Postcode: '.$postcode.' Branche: '.$branche.' Telefoonnummer: '.$telefoon.' vraag of Wens: '.$message.' |---------End Message----------|'; echo "thank you for your request we will contact you asap."; mail($to, $subject, $body); } else { echo "Error Please <a href='form.html'>try again</a>"; } ?> Any help would be great! Thanks guys i have an html form which is a "post" on it i have an array of checkboxes and a sumbit button, once button is clicked i go to another page where i handle those boxes checked the problem now is if NO checkboxes are checked and i hit the submit...i get errors on the other page my code: foreach($product_names as $product_row) { ?> <tr> <td > </td><td width='200px'><?php echo $product_row->getName(); ?></td> <td width='200px'><input type="checkbox" name="graphic[]" value="<?php echo $product_row->getId();?>" /></td> <td width='200px'><input type="checkbox" name="text[]" value="<?php echo $product_row->getId();?>" /></td> </tr> <?php } ?> </table> <table> <tr> <td> <input type='submit' name='submit' value='Submit'> <?php if ( (isset($graphic)) || (isset($text) )) { echo "checkboxes checked"; //show submit button } else { //hide submit botton and echo "no boxes check"; } ?> the above is NOT working please help???? Hello,
I want to show checkbox is checked when there is entry of that id in a table in my database.
I have 2 tables page and access_level. I am getting data from page table and displays it in <ul><li> tag with checkbox to select all or only few. After selecting the checkbox, i will store only selected checkbox value in access_level table along with table id. Page link and page name details will be stored in page table.
Now if i want to edit , i should display all the pages which is there in page table and i should also mark checked to those which are already stored in access_level table.
I am using LEFT OUT JOIN, It displays all the pages. But it is not displaying the check mark to those which are already selected.
Here is my code
<?php $s1 = mysql_query("SELECT pages.page_id, pages.code, pages.page, pages.href, access_level.aid, access_level.page_id as pgid, access_level.department, access_level.position, access_level.active FROM pages LEFT OUTER JOIN access_level ON pages.page_id=access_level.page_id WHERE access_level.department=".$department." AND access_level.position=".$position." AND pages.code='sn'") or die(mysql_error()); while($s2 = mysql_fetch_array($s1)) { ?> <tr><td><li><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['page_id']; ?>" <?php if($row['pgid'] === $s2['page_id']) echo 'checked="checked"';?> />here is my pages table pages.JPG 26.55KB 0 downloads access_level access_level.JPG 19.09KB 0 downloads In access_level table i do not have page ids 8 and 9. But i want to display that also from pages table and for 1 to 7 and 10 i should display check mark. How i can achieve this? Please Help I need bit of help, so I am looking into a plugin created for newsletter where default is it shows ad but it has option to remove ads by checking the check box. Default is to send ads in newsletter but if you don't want to send ads through newsletter then check the box. The problem is, it seems like checkbox selected is not being picked up. Some help would be appreciated. The custom field in wp:
'label' => 'Hide newsletter ads', 'name' => 'hide_ads', 'type' => 'checkbox', 'instructions' => 'Checking the checkbox will remove ads', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'choices' => array( 'Hide newsletter ads' => 'Hide newsletter ads', ), 'allow_custom' => 0, 'default_value' => array( ), 'layout' => 'block', 'toggle' => 0, 'return_format' => 'value', 'save_custom' => 0, ),
This is the php code for it: <!doctype html> <html lang="en-GB"> <head> <meta name="viewport" content="width=device-width" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="x-apple-disable-message-reformatting"> <title><?php the_title(); ?></title> <style> <?php require ABSPATH . 'path/newsletter.css'; ?> </style> <!--[if mso]> <style type="text/css"> .outlook-fallback-font { font-family: 'Lucida Bright', 'Cambria', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; } </style> <![endif]--> </head> <?php $hide_newsletter_ads = get_field('hide_ads'); echo $hide_newsletter_ads; ?> <body itemscope itemtype="http://schema.org/EmailMessage"> <div class="wrap"> <?php if (!$hide_newsletter_ads) { include ABSPATH . 'path/ad-banner.php'; } ?> <div class="header"> <a href="<?php bloginfo( 'url' ); ?>"> <img src="<?php echo get_home_url().'logo.png' ?>" alt="News" /> </a> </div> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if ( get_field( 'newsletter_summary' ) ) { ?> <div class="newsletter-summary"><?php the_field( 'newsletter_summary' ); ?></div> <?php } ?> <?php if ( have_rows( 'newsletter_content' ) ) : ?> <?php // Loop through the ACF blocks $count = 0; while ( have_rows( 'newsletter_content' ) ) : the_row(); if ( get_row_layout() === 'story' ) : ?> <?php if ( 0 === $count ) { ?> <span class="date outlook-fallback-font"><?php the_time( 'd M Y' ); ?></span> <?php } ?> <?php if ( get_sub_field( 'story_heading' ) ) : ?> <h1><?php the_sub_field( 'story_heading' ); ?></h1> <?php endif; ?> <div class="content"> <?php the_sub_field( 'story_content' ); ?> </div> <?php endif; if ( 'post_list' === get_row_layout() ) : ?> <?php $posts = get_sub_field( 'post_list' ); if ( $posts ) : ?> </div> <div class="story-list"> <h2><span class="wrap"><?php the_sub_field( 'post_list_heading' ); ?></span></h2> <div class="wrap-table"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <?php // Output story cards foreach ( $posts as $i => $post ) { if ( 0 === $i % 2 ) { echo '<tr>'; } $class = ( 0 === $i % 2 ) ? 'odd' : 'even'; $image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( 640, 345 ) ); $image_srcset = wp_get_attachment_image_srcset( get_post_thumbnail_id( $post->ID ) ); echo sprintf( '<td class="story-cell %4$s" valign="top"> <a href="%1$s" class="story-card outlook-fallback-font"> <img src="%3$s" alt="" height="120" style="height: 150px; object-fit: cover;" /> <span>%2$s</span> </a> </td>', esc_url( get_permalink( $post->ID ) . '?utm_source=newsletter&utm_medium=email&utm_campaign=newsletter' ), // permalink esc_html( get_the_title( $post->ID ) ), // title // esc_attr( $image_src[0] ), // image - src esc_attr( $image_src[0] ), // image - src esc_attr( $class ) // class ); if ( 0 !== $i % 2 || count( $posts ) === ( $i + 1 ) ) { echo '</tr>'; } } ?> </table> </div> </div> <div class="wrap"> <?php endif; endif; if (!$hide_newsletter_ads) { (0 === $count) { include ABSPATH . 'path/mpu-1.php'; } if (1 === $count) { include ABSPATH . 'path/mpu-2.php'; } } $count++; endwhile; endif; ?> <div class="footer"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="left"> © <?php echo esc_html( date( 'Y' ) ); ?> </td> <td class="footer-link"> <a href="<?php echo get_permalink( get_page_by_path( 'privacy-policy' ) ); ?>">Privacy Policy</a> · <a href="%unsubscribe_url%">Unsubscribe</a> </td> </tr> </table> </div> </div> <?php endwhile; endif; ?>
I am simply trying to keep a check box checked once selected. What I have works, but not correctly. Because I am calling each array element in my checkbox like name="checkbox[]" And I am using this as the input return the check: <input type="checkbox" name="checkbox[]" value="checkOneValue" <?php if(isset($_POST['checkbox'])) echo "checked"; ?> /> I have 5 checkboxes that use the same code! And as I said it works, but returns ALL checkboxes as selected when submitted. I only want the actual selected boxes to remained checked. Any insight on a work around? The problem is I cannot solve how to identify unique array values as they are all named the same... Maybe I am not thinking right on all of this. Here is my full source code: <!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>Checkbox Echoing Test</title> </head> <body> <form name="" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> One <input type="checkbox" name="checkbox[]" value="checkOneValue" <?php if(isset($_POST['checkbox'])) echo "checked"; ?> /> <br /> Two <input type="checkbox" name="checkbox[]" value="checkTwoValue" <?php if(isset($_POST['checkbox'])) echo "checked"; ?> /> <br /> Three <input type="checkbox" name="checkbox[]" value="checkThreeValue" <?php if(isset($_POST['checkbox'])) echo "checked"; ?> /> <br /> Four <input type="checkbox" name="checkbox[]" value="checkFourValue" <?php if(isset($_POST['checkbox'])) echo "checked"; ?> /> <br /> Five <input type="checkbox" name="checkbox[]" value="checkFiveValue" <?php if(isset($_POST['checkbox'])) echo "checked"; ?> /> <br /> <input type="submit" name="submit" value="Echo Checkbox Data!" /> </form> <?php if (isset($_POST['checkbox']) && (isset($_POST['submit']))) { $checkbox = $_POST['checkbox']; foreach ($checkbox as $checkboxValue) { var_dump($checkboxValue); if (!empty($checkboxValue)) { echo "<br />$checkboxValue is checked"; } } }; // End of foreach loop if (!isset($_POST['checkbox']) && (isset($_POST['submit']))) { echo "<br />No checkboxes were selected!"; }; ?> </body> </html> Hi I am new to php, I am trying to capture the url and place into a variable but I only get the 1st digit to show, I just cant see what I am doing wrong. Sorry to ask such a basic question but I just can't work it out, I have attached a screen shot of all me code, your help would be very very much appreciated. I'm having troubling with trying to create a function to spit out a single array with the following array. I can write it in a away that looks through the arrays manually. the results i am trying to generate is that each item in generated array. Array to convert array( "account" => array( "login", "register", "logout", "edit", ), "p" => array( "report", ), "array1.0" => array( "array2.0" => array( "array3.0", "array3.1 ), "array2.1", ), generating the array will look like this
Array ( [0] => account [1] => account/login [2] => account/register [3] => account/logout [4] => account/edit [5] => p [6] => p/report [7] => array1.0 [8] => array1.0/array2.0 [9] => array1.0/array2.0/array3.0 [10] => array1.0/array2.0/array3.1 [11] => array1.0/array2.1 ) The idea is that id generates a single array with combined labels and arrays inside, etc. I just can't figure out how to create a script that will create this array even If I add a new value or array.
I have this thing that i am trying to make but i cant get it to work.. can anyone help? Code: [Select] function sql_read( $dbname,$dbusername,$dbpassword ) { $names = array(); $password = array(); $connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect"); @mysql_select_db ($dbname) or die("Could not find DataBase"); $query = mysql_query("select * from users"); $numrows = mysql_num_rows($query); if ($numrows > 0){ while($row = mysql_fetch_assoc($query)){ $names[] = $row["uname"]; $password[] = $row["password"]; $id = $row["id"]; } $return = array($names,$password,$id); }else{ $return = array(); } return $return[]; } $names = array(); $names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0]; The error i get is Code: [Select] Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28 Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];" Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks! I have two arrays, both with the same key values. I'd like to combine them. So for instance... Code: [Select] <?php $array1['abcd'] = array( 'value1' => "blah", 'value2' => "blahblah"); $array1['efgh'] = array( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz"); $array2['abcd'] = array('value3' => "three", 'value4' => "four"); $array2['efgh'] = array( 'value3' => "hohoho", 'value6' => "six6"); function combine_arrays($array1,$array2) { //*combining* return $single_array; } echo "<pre>"; print_r(combine_arrays($array1,$array2)); echo "</pre>"; /* would produce ['abcd'] = ( 'value1' => "blah", 'value2' => "blahblah", 'value3' => "three", 'value4' => "four" ) ['efgh'] = ( 'value1' => "ha", 'value2' => "haha", 'valuex' => "xyz", 'value3' => "hohoho", 'value6' => "six6" ) */ ?> What's the easiest way to do this? |