Jump to content

azukah

Members
  • Posts

    55
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

azukah's Achievements

Member

Member (2/5)

0

Reputation

  1. got a reply in another forum... $q = mysql_query("SELECT sec_id, sec_name, sec_group FROM tbl_user_sec ORDER BY sec_id"); $groups = Array(); while($w = mysql_fetch_assoc($q)) { if(!isset($groups[$w['sec_group']])) $groups[$w['sec_group']] = Array(); $groups[$w['sec_group']][] = $w; } echo "<ul>"; foreach($groups as $group_name => $sections) { echo '<li><a href="#">'.$group_name.'</a><ul>'; foreach($sections as $section) { echo '<li><a href="#">'.$section['sec_name'].'</a>'; } echo '</ul></li>'; } echo "</ul>"; http://stackoverflow.com/questions/12239995/how-to-create-dynamic-menu-with-sub-menu-with-php-mysql
  2. Hi- I want to have a dynamic menu that feeds from a table using php and mysql. My table looks like this: sec_id sec_name sec_group 1 section 1 group 1 2 section 2 group 1 3 section 3 group 2 4 section 4 group 1 5 section 5 group 3 I can do a query to get and display unique sec_group values but can't figure out a way to include sec_name into each sec_group //Query by unique sec_group $qry_secs="SELECT DISTINCT sec_group FROM tbl_user_sec ORDER BY sec_id ASC"; $result_secs = mysql_query($qry_secs); //echo values while($row_secs = mysql_fetch_assoc($result_secs)){ echo '<ul><li><a href="#">'.$row_secs['sec_group'].'</a></li></ul>'; } Eventually, the HTML should like the code below. <ul> <li><a href="#">Group 1</a> <ul> <li><a href="#">Section 1</a></li> <li><a href="#">Section 2</a></li> <li><a href="#">Section 4</a></li> </ul> </li> <li><a href="#">Group 2</a> <ul> <li><a href="#">Section 3</a></li> </ul> </li> <li><a href="#">Group 3</a> <ul> <li><a href="#">Section 5</a></li> </ul> </li> </ul> Any ideas???
  3. it works now :D here's the complete code: //this is the submit button in offer.php <form action="process.php" method="post" name="myform"> <input id="submit" type="submit" value="submit"/> </form> //this process.php <?php $data = array("account" => "{$account}", "dob" => "{$dob}", "site" => "{$site}"); $data_string = json_encode($data); $ch = curl_init("http://somewebservice.com/{$PrizeID}"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string)) ); $result = curl_exec($ch); curl_close($ch); $json_result = json_decode($result, true); ?> // here's the call for the confirmation number <p>Your confirmation number is: <strong><?php echo $json_result['ConfirmationCode'];?></strong></p>
  4. i was playing with php and curl and managed to make it work till it does write to the DB via the web service which is great what i need now is to get the ConfirmationCode and no idea how to do that... i'll put another post for the confirmationcode part because this has run a bit long. here's the updated code (from attempt 3) //this is from offer.php file <form action="process.php" method="post" name="myform"> <input id="submit" type="submit" value="submit"/> </form> //here's the php with Curl in process.php <?php $data = array("account" => "{$account}", "dob" => "{$dob}", "site" => "{$site}"); $data_string = json_encode($data); $ch = curl_init("http://somewebservice.com/{$PrizeID}"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string)) ); $result = curl_exec($ch); curl_close($ch); ?>
  5. thanks again. //$PrizeID comes from previous page //and i changed the the other 3 to $_POST['account']; $_POST['dob']; $_POST['site']; i also removed the variable and coded the actual values and got the same results. Here's the updated ocde: <?php //get PrzeID if (isset($_GET['PrizeID'])) { $PrizeID = $_GET['PrizeID']; } //POST if(isset($_POST['submit'])){ $options = array( 'http'=>array( 'method'=>"POST", 'contentType'=>"application/x-www-form-urlencoded", 'content'=>http_build_query(array( 'account' => $_POST['account'], 'dob' => $_POST['dob'], 'site' => $_POST['site'] )) )); $context = stream_context_create($options); $result = file_get_contents("http://somewebservice.com/{$PrizeID}",NULL,$context); var_dump($result); $json_result = json_decode($result); } ?> <!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" xml:lang="en" lang="en"> <head> </head> <body> <form name="myform" method="post"> <input name="account" id="account" type="hidden" value="<?php echo $account;?>"/> <input name="dob" id="dob" type="hidden" value="<?php echo $dob;?>"/> <input name="site" id="site" type="hidden" value="<?php echo $site;?>"/> <input id="submit" type="submit" value="submit"/> </form> <div id="result"> <p><?php echo json_encode($_POST);?></p> </div> </body> </html> Here are the results I get when I add name="submit" to the form submit button: bool(false) {"account":"300207601","dob":"12\/12\/2012","site":"HLY","submit":"submit"} when i don't have name="submit", i don't get bool(false) and this is the echo for json_encode($_POST) {"account":"300207601","dob":"12\/12\/2012","site":"HLY"}
  6. thanks! i got this error bool(false) when i echo'd $context, i got "Resource id #4"
  7. this is all the code i have... <?php if(isset($_POST['submit'])){ $options = array( 'http'=>array( 'method'=>"POST", 'contentType'=> "application/x-www-form-urlencoded", 'content'=>http_build_query(array( 'account' => $account, 'dob' => $dob, 'site' => $site )) )); $context = stream_context_create($options); $result = file_get_contents("http://somewebservice.com/{$PrizeID}",NULL,$context); var_dump($result); } ?> <!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" xml:lang="en" lang="en"> <head> <title>Reserve</title> </head> <body> <form name="myform" method="post"> <input name="account" id="account" type="hidden" value="<?php echo $account;?>"/> <input name="dob" id="dob" type="hidden" value="<?php echo $dob;?>"/> <input name="site" id="site" type="hidden" value="<?php echo $site;?>"/> <input id="submit" type="submit" value="submit"/> </form> </body> </html>
  8. oh! makes sense. thanks. i changed it but no luck. 'contentType'=> "application/x-www-form-urlencoded",
  9. hi- i added post method to the form and content type to php and still not working. no idea what's wrong <form name="myform" method="post"> <input name="account" id="account" type="hidden" value="<?php echo $account;?>"/> <input name="dob" id="dob" type="hidden" value="<?php echo $dob;?>"/> <input name="site" id="site" type="hidden" value="<?php echo $site;?>"/> <input id="submit" type="submit" value="submit"/> // if(isset($_POST['submit'])){ $options = array( 'http'=>array( 'method'=>"POST", 'contentType'=> "application/json", 'content'=>http_build_query(array( 'account' => $account, 'dob' => $dob, 'site' => $site )) )); $context = stream_context_create($options); $result = file_get_contents("http://somewebservice.com/{$PrizeID}",NULL,$context); var_dump($result); }
  10. I do have access to the web service log. Ill try again as soin as i get home and will let u know. Thanks.
  11. @seanlIm: no, it doees't. It only appears in the web service log when submit via browser (attemp 1).
  12. @Seanlim: thanks. i didnt notice that. I added POST as method and still same result
  13. Hi- I have to post to a URL, grab one field our of the JSON output/response and format nicely to the user. I've tried a few things with some help but none seem to be working. So any help or direction would be greatly appreciate it!! Attempt 1 (works but not formatted nicely) if I post using the browser, it works. the data is sent to the URL (web service) and I can see in the web service logs that the entry has been recorded. the problem is that since i have the URL in "action", i'm taken to that page and the user gets to see the JSON output //here's the HTML form in offer.php <form action="http://somewebservice.com/<?php echo $PrizeID;?>" method="post" name="myform"> <input name="account" id="account" type="hidden" value="<?php echo $account;?>"/> <input name="dob" id="dob" type="hidden" value="<?php echo $dob;?>"/> <input name="site" id="site" type="hidden" value="<?php echo $site;?>"/> <input id="submit" type="submit" value="submit"/> </form> //here's the output (JSON) after clicking submit {"Prize":"XXXXXX","ConfirmationCode":"######","Error":false,"ErrorMsg":null} Attempt 2 (doens't work) i tried using php but after submit, the page refreshes and no entry is recorded in the web service log //here's the HTML form in offer.php <form name="myform"> <input name="account" id="account" type="hidden" value="<?php echo $account;?>"/> <input name="dob" id="dob" type="hidden" value="<?php echo $dob;?>"/> <input name="site" id="site" type="hidden" value="<?php echo $site;?>"/> <input id="submit" type="submit" value="submit"/> //here's the php in offer.php <?php if(isset($_POST['submit'])){ $options = array( 'http'=>array( 'method'=>"POST", 'content'=>http_build_query(array( 'account' => $account, 'dob' => $dob, 'site' => $site )) )); $context = stream_context_create($options); $result = file_get_contents("http://somewebservice.com/{$PrizeID}",NULL,$context); var_dump($result); } ?> Last attempt (doesn't work) i tried using php & curl so that i can process in the back and show only the ConfirmationCode to the user in a nice format but it doesn't work. after submit, i'm taken to process.php where i see nothing and no entry is recorded in the web service log //here's the HTML form in offer.php <form action="process.php" method="post" name="myform"> <input name="account" id="account" type="hidden" value="<?php echo $account;?>"/> <input name="dob" id="dob" type="hidden" value="<?php echo $dob;?>"/> <input name="site" id="site" type="hidden" value="<?php echo $site;?>"/> <input id="submit" type="submit" value="submit"/> </form> //here's the PHP in process.php <?php $postvars=file_get_contents("php://input"); $curl=curl_init("http://somewebservice.com/{$PrizeID}"); curl_setopt($curl,CURLOPT_POSTFIELDS,$postvars); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result=curl_exec($curl); $decodedresult=json_decode($result,true); ?> i haven't gotten to the point where i grab the ConfirmationCode I want because i want to get this fixed first and also because i can't get that to work but will focus on that once i fix this. Thanks.
  14. sorry for the messy code, i was trying different things and forgot to delete some stuff. i cleaned it up and changed it to a for loop and it works
  15. i have a slider that shows 2 images at a time. i did a query and got all my images names from the database to be in an array so i can go form index zero to the last image incrementing by +1 but not working. what it is doing now is displaying index[0] and index[1] in the first set of 2 images in the second set is displaying index[1] and index [2] in the third set is displaying index[2] and index[3] and so on... here's my query require_once('connections.php'); mysql_select_db($dbname, $db); $sql = "SELECT * FROM table WHERE image IS NOT NULL LIMIT 6"; //limiting to six for testing only, will remove afterwords $results = mysql_query($sql, $db) or die(mysql_error()); $row = mysql_fetch_assoc($results); // $result2 = mysql_query("SELECT * FROM table WHERE image IS NOT NULL LIMIT 6"); $storeArray = Array(); while ($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) { $storeArray[] = $row2['image']; } ?> here's the html/php <?php $index = 0;?> <?php do { ?> <div class="slide"> <div class="slidePromo"> <div class="promoImg"><a href="#"><img src="<?php echo $storeArray[$index];?>"/></a> </div> </div> <!--end slide--> <div class="slidePromo"> <div class="promoImg"><a href="#l"><img src="<?php echo $storeArray[++$index];?>"/></a></div> </div> </div> <!--end slide--> <?php } while ($row = mysql_fetch_assoc($results)); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.