PHP - Pulling Mysql Data For Check Boxes And Radio Buttons.
Hey!
I have it so users can submit info to my site. They have to check some check boxes and radio buttons. I want them to be able to edit this information, so I want to have the data pulled from the MySQL database and have the correct radio button selected (and the text bolded). So I'm thinking some sort of array to check for each value in the database... but I don't really know. There are a few groups of radio boxes and check boxes but here is an example of one. Code: [Select] <input type="radio" name="stage" value="Stage 1" /> Stage 1 <input type="radio" name="stage" value="Stage 2" /> Stage 2 <input type="radio" name="stage" value="Stage 3" /> Stage 3 The information is pulled from the database like this: Code: [Select] $res=mysql_query("SELECT * FROM ACTIVE WHERE INDEX_ID=$id"); if(mysql_num_rows($res)==0) echo "There is no data in the table <br /> <br />"; else { for($i=0;$i<mysql_num_rows($res);$i++) { $row=mysql_fetch_assoc($res); } } So when I pull information (lets say I want to echo it) it'd look like this: Code: [Select] $row[STAGE] The value for the stage selection can only be Stage 1, Stage 2 or Stage 3 so I need it to be selected when the page loads. Thanks! Similar TutorialsHi guys...I need some help in matching data from results of checkboxs and radio buttons. My Intentions: There are 3 radio buttons and 8 check boxes. Users can select any one but cannot don't select at all. I separate the calss and categories because for classes, users can only select 1 option whereas for categories users can select many. For example, User select class 1 but do not select anything else and click submit...the system will then retrieve that he selected and check the data base if he have the pre requisites to allow him to go through. Coding for my form: Code: [Select] <form id="applicationoptions" method="post" action="s_apply_now.php"> <div id="optionshead">Class :</div> <div id="classoptions"> <input type="radio" name="class" value="1" /> Class 1 Permit <input type="radio" name="class" value="2" /> Class 2 Permit <input type="radio" name="class" value="3" /> Class 3 Permit </div> <div id="optionshead2">Categories :</div> <div id="catoptions"> <input type="checkbox" name="cat" value="1" /> CAT 2PG <input type="checkbox" name="cat" value="2" /> CAT 1OR <input type="checkbox" name="cat" value="3" /> CAT 2TT <br/><br/> <input type="checkbox" name="cat" value="4" /> CAT 3PG <input type="checkbox" name="cat" value="5" /> CAT 2OR <input type="checkbox" name="cat" value="6" /> CAT 3TT <br/><br/> <input type="checkbox" name="cat" value="7" /> CAT 4PG <input type="checkbox" name="cat" value="8" /> CAT 3OR </div> <div class="applynext"> <input class="applynextbutton" type="submit" name="applynextbutton" value="PROCEED" /> </div> </form> Lets say if user do not select any class, but select CAT 3PG, system will check if user have the pre-requisites before proceeding to next step. Any one can help me or give me hints?? most importantly is i do not know how to retreieve the values selected from the form. Is it possible to do it using php or must i hunt for javascript's script?? Thanks in advance guys...greatly appreciate. Hi. Im pretty sure this is easy but ive been trying for hours and looked all over the web but cant seem to do it. I have information submitted to my database which I then retrieve on another page. I retrieve the landlord name and group the same values together plus retrieve an overall rating which I average and sort by. This works and is done using: Code: [Select] $sql="SELECT landlord_name, AVG(overall) FROM $tbl_name GROUP BY landlord_name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ Where Im finding it difficult though is I have 5 radio buttons with values from 1-5 and want one of them to be checked if the value matches the averaged overall rating. What I've tried is: Code: [Select] if (AVG(overall)==1){ $check1="checked";} if (AVG(overall)==2){ $check2="checked";} if (AVG(overall)==3){ $check3="checked";} if (AVG(overall)==4){ $check4="checked";} if (AVG(overall)==5){ $check5="checked";} then in the form: Code: [Select] <table width="600" border="1" cellspacing="0" cellpadding="3"> <tr> <td><? echo $rows['landlord_name']; ?></td> <td><div class="avg"><form> <input type="radio" value="1" disabled="disabled" checked= "<? $check1 ?>" /> <input type="radio" value="2" disabled="disabled" checked= "<? $check2 ?>" /> <input type="radio" value="3" disabled="disabled" checked= "<? $check3 ?>" /> <input type="radio" value="4" disabled="disabled" checked= "<? $check4 ?>" /> <input type="radio" value="5" disabled="disabled" checked= "<? $check5 ?>"/> </form></div> </td> </tr> </table> To make it a bit more difficult, the AVG(overall) value will not always be an integer from 1-5 and will need to be rounded to the closest one. Think i can use ROUND for this but dont know how to put it in. Thanks for your help in advance. As you can probably tell im new to php and still learning the basics. Code: [Select] id: 20 Reason: this is a test id: 21 Reason: Tests id: 22 Reason: Lolcatz id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: Reason: id: 36 Reason: Test As you can see on the 2nd code box there are id's 20,21,22 and 36 in the database the rest are not active in the database. i am using using Code: [Select] for to pull out the id that starts with the lowest value in the database, and only have it run until it gets to the maximum value. Code: [Select] for ($id=$set_min; $set_max<=7; $id++) { // $id=$set_min is pulling the smallest value and $set_max is pulling the maximum value so it stops after it gets to 36 $query=mysql_query("SELECT * FROM posted WHERE id = $id"); $query_row=mysql_fetch_array($query); $reason = $query_row[reason]; $pulled_id = $query_row[id]; $pulled_pic22 = $query_row[picture]; $href_pull = "<a href=" . "search.php?id=" . "$id" .">"; echo "<td>" . $href_pull . "<img src=$pulled_pic22 height=200 width=150 />" . "</td>"; } how would i make it so i do not pull the values 23-35 which are not in the active database. Example: http://dev.hackmuch.com/of-the-day/search.php?id=36 im developing a voting system where you can vote for multiple choices using checkboxes.. upon submitting the vote form, votecounts must automatically be updated.. values for votecount will come from the checkbox value 1. ive been having a hard time trying to figure out hot to update multiple rows with checkbox values..any help would be appreciated..thanks in advance! here's the code: Code: [Select] $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form_vote")) $i=1;{ while ($i<= $totalRows_rs_candi) { $updateSQL = "UPDATE tbl_candidates SET votecount={$_POST['votecount']} WHERE user_id={$_POST['candi']}"; mysql_select_db($database_organizazone_db, $organizazone_db); $Result1 = mysql_query($updateSQL, $organizazone_db) or die(mysql_error()); $i++; } if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo = "vote_success.php"; } header(sprintf("Location: %s", $updateGoTo)); } Code: [Select] <form id="form_vote" name="form_vote" method="POST" action="<?php echo $editFormAction; ?>"> <table border="1"> <tr> <td> </td> <td>user_id</td> <td>l_name</td> <td>course_id</td> <td>yearlevel</td> <td>about</td> </tr> <?php $i=1; do { ?> <tr> <td><span id="sprycheckbox1"> <input name="votecount[<?php echo $i ?>]" type="checkbox" id="votecount" value="1" /> <span class="checkboxMinSelectionsMsg">Minimum number of selections not met.</span></span> <label for="votecount[]"></label></td> <td><label for="candi"></label> <input name="candi" type="text" disabled="disabled" id="candi" value="<?php echo $row_rs_candi['user_id']; ?>" readonly="readonly" /></td> <td><?php echo $row_rs_candi['l_name'].' ,'.$row_rs_candi['f_name'].' '.$row_rs_candi['m_name']; ?></td> <td><?php echo $row_rs_candi['course_id']; ?></td> <td><?php echo $row_rs_candi['yearlevel']; ?></td> <td><?php echo $row_rs_candi['about_me']; ?></td> </tr> <?php $i++; ?> <?php } while ($row_rs_candi = mysql_fetch_assoc($rs_candi)); ?> </table> Hi, I have a table that contains posts and each post has a datetime field. Im trying to work out how I can show entries from today, this week and this month so I can have a link that shows all posts from today or this month etc. Any one know how I can do this ? My current piece of code that pulls the data from the db looks like this : Code: [Select] $texts= mysql_query("SELECT * FROM submittedtexts Order by id DESC LIMIT " . (($page - 1) * 6) . ", 6"); I want to add a bit that acts like : WHERE date = today Hope that makes sense, Im a bit of a newbie Thanks in advance, Scott I'm in the process of making a network for investors and entrepreneurs. When they access their profile page, select edit and go to editprofile.php a problem arises with the data base submission. I have the data they have previously inputted being echoed back out to the user. This lets the user see what they have inputted so that they can make changes to their profile. Unfortunately, with my radio buttons, if no changes are made and the user hits submit, the radio buttons return a value of 'unchecked'. I need them to maintain the value previously submitted to the database if the radio button isn't 'checked'. I'm not sure exactly how to do this. You can test it out yourself by going to http://network.jasonbiondo.com Code is below: Code: [Select] ?php session_start(); require ('connect.php'); include ('header.php'); $savechanges = $_POST['savechanges']; $firstname = strip_tags($_POST['firstname']); $lastname = strip_tags($_POST['lastname']); $username = strtolower(strip_tags($_POST['username'])); $email = strip_tags($_POST['email']); $password = strip_tags($_POST['password']); $repeatpassword = strip_tags($_POST['repeatpassword']); $entrepreneur = 'unchecked'; $investor = 'unchecked'; $date = date("Y-m-d"); $companyname = strip_tags($_POST['companyname']); $companywebsite = strip_tags($_POST['companywebsite']); $founder = strip_tags($_POST['founder']); $phone = strip_tags($_POST['phone']); $address = strip_tags($_POST['address']); $city = strip_tags($_POST['city']); $state = strip_tags($_POST['state']); $zipcode = strip_tags($_POST['zipcode']); $country = strip_tags($_POST['country']); $development = strip_tags($_POST['development']); $capitalamount = strip_tags($_POST['capitalamount']); $companydo = strip_tags($_POST['companydo']); $founderbuilt = strip_tags($_POST['founderbuilt']); $whatsnew = strip_tags($_POST['whatsnew']); $understand = strip_tags($_POST['understand']); $competition = strip_tags($_POST['competition']); $money = strip_tags($_POST['money']); $demo = strip_tags($_POST['demo']); $incorporation = strip_tags($_POST['incorporation']); $companynameinv = strip_tags($_POST['companynameinv']); $phoneinv = strip_tags($_POST['phoneinv']); $addressinv = strip_tags($_POST['addressinv']); $cityinv = strip_tags($_POST['cityinv']); $stateinv = strip_tags($_POST['stateinv']); $zipcodeinv = strip_tags($_POST['zipcodeinv']); $countryinv = strip_tags($_POST['countryinv']); $angel = strip_tags($_POST['angel']); $vc = strip_tags($_POST['vc']); $capital = strip_tags($_POST['capital']); if ($savechanges) { $queryreg = mysql_query("UPDATE users SET `firstname` = '$firstname', `lastname` = '$lastname', `email` = '$email', `entrepreneur` = '$entrepreneur', `investor` = '$investor', `companyname` = '$companyname', `companywebsite` = '$companywebsite', `founder` = '$founder', `phone` = '$phone', `address` = '$address', `city` = '$city', `state` = '$state', `zipcode` = '$zipcode', `country` = '$country', `development` = '$development', `capitalamount` = '$capitalamount', `companydo` ='$companydo', `founderbuilt` = '$founderbuilt', `whatsnew` = '$whatsnew', `understand` = '$understand', `competition` = '$competition', `money` = '$money', `demo` = '$demo', `incorporation` = '$incorporation', `companynameinv` = '$companynameinv', `phoneinv` = '$phoneinv', `addressinv` = '$addressinv', `cityinv` = '$cityinv', `stateinv` = '$stateinv', `zipcodeinv` = '$zipcodeinv', `countryinv` = '$countryinv', `angel` = '$angel', `vc` = '$vc', `capital` = '$capital' WHERE username= '" . $_SESSION['username'] . "' "); $selected_radio_selector = $_POST['selector']; $selected_radio_invtype = $_POST['invtype']; if ($selected_radio_selector == 'entrepreneur') { $entrepreneur = 'checked'; } else if ($selected_radio_selector == 'investor') { $investor = 'checked'; if ($selected_radio_invtype == 'angel') { $angel = 'checked'; $vc = 'unchecked'; } else if ($selected_radio_invtype == 'vc') { $vc = 'checked'; $angel = 'unchecked'; } else { die("Please select what type of investor you are!"); } } } $q = mysql_query("SELECT `firstname`, `lastname`, `firstname`, `lastname`, `email`, `entrepreneur`, `investor`, `companyname`, `companywebsite`, `founder`, `phone`, `address`, `city`, `state`, `zipcode`, `country`, `development`, `capitalamount`, `companydo`, `founderbuilt`, `whatsnew`, `understand`, `competition`, `money`, `demo`, `incorporation`, `companynameinv`, `phoneinv`, `addressinv`, `cityinv`, `stateinv`, `zipcodeinv`, `countryinv`, `angel`, `vc`, `capital` FROM `users` WHERE username= '" . $_SESSION['username'] . "'"); $r = mysql_fetch_assoc($q); ?> <script type="text/javascript" src="../assets/js/editprofile.js"></script> <form action='editprofile.php' method="POST" id="form"> <fieldset> <p id="required"> * Required Fields</p> <p class="fieldSpacing"> <label for="firstname" class="leftcolalign">First Name *</label> <input id="firstname" class="rightcolalign" name="firstname" value='<?php echo $r['firstname']; ?>'/> </p> <p class="fieldSpacing"> <label for="lastname" class="leftcolalign">Last Name *</label> <input id="lastname" class="rightcolalign" name="lastname" value='<?php echo $r['lastname'];?>'/> </p> <p class="fieldSpacing"> <label for="username" class="leftcolalign">User Name *</label> <?php echo $_SESSION['username']; ?> </p> <p class="fieldSpacing"> <label for="email" class="leftcolalign">Email *</label> <input id="email" class="rightcolalign" name="email" value='<?php echo $r['email']; ?>''/> </p> <p class="fieldSpacing"> <label for="selector" class="leftcolalign">What am I? *</label> <input id="entButton" class="radioalign" type="radio" name="selector" value="entrepreneur"<?php echo $r['entrepreneur']; ?>/> <label for="entrepreneur" id="entrepreneur">Entrepreneur</label> <input id="invButton" class="radioalign" type="radio" name="selector" value="investor"<?php echo $r['investor']; ?>/> <label for="investor" id="investor">Investor</label> </p> </fieldset> <fieldset id="entForm"> <p class="fieldSpacing"> <label for="companyname" class="leftcolalign">Company Name: *</label> <input id="companyname" class="rightcolalign" name="companyname" value='<?php echo $r['companyname']; ?>'/> </p> <p class="fieldSpacing"> <label for="companywebsite" class="leftcolalign">Company Website:</label> <input id="companywebsite" class="rightcolalign" name="companywebsite" value='<?php echo $r['companywebsite']; ?>'/> </p> <p class="fieldSpacing"> <label for="founder" class="leftcolalign">Founder(s): *</label> <input id="founder" class="rightcolalign" name="founder" value='<?php echo $r['founder']; ?>'/> </p> <p class="fieldSpacing"> <label for="phone" class="leftcolalign">Phone Number(s): *</label> <input id="phone" class="rightcolalign" name="phone" value='<?php echo $r['phone']; ?>'/> </p> <p class="fieldSpacing"> <label for="address" class="leftcolalign">Address: *</label> <input id="address" class="rightcolalign" name="address" value='<?php echo $r['address']; ?>'/> </p> <p class="fieldSpacing"> <label for="city" class="leftcolalign">City: *</label> <input id="city" class="rightcolalign" name="city" value='<?php echo $r['city']; ?>'/> </p> <p class="fieldSpacing"> <label for="state" class="leftcolalign">State:</label> <input id="state" class="rightcolalign" name="state" value='<?php echo $r['state']; ?>'/> </p> <p class="fieldSpacing"> <label for="zipcode" class="leftcolalign">Zip Code:</label> <input id="zipcode" class="rightcolalign" name="zipcode" value='<?php echo $r['zipcode']; ?>'/> </p> Hi guys, I'm recent working on my php to add the row in mysql database. I need a bit of your help as I would like to know how to check the data in mysql database if it have added in mysql and then print it out without adding another same row? here's the current code: Code: [Select] <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $pass = clean($_GET['pass']); $login = clean($_GET['login']); $all = clean($_GET['all']); if($username == '' && $pass == ''){ // both are empty $errmsg_arr[] = 'Username and password are missing. You must enter both or the other one.'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $insert = array(); if(isset($_GET['user'])) { $insert[] = 'username = \'' . clean($_GET['user']) .'\''; } if(isset($_GET['pass'])) { $insert[] = 'pass = \'' . clean($_GET['pass']) . '\''; } if(isset($_GET['login'])) { $insert[] = 'LoggedUser = \'' . clean($_GET['login']) . '\''; } if(isset($_GET['all'])) { $insert[] = 'all = \'' . clean($_GET['all']) . '\''; } if (count($insert)>0) { $names = implode(',',$insert); if($username) { $qrytable1="SELECT username, LoggedUser FROM Online_Users WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "<p id='LoggedUser'>"; echo $row['LoggedUser'] . "</p>"; } } if($username && $login == '1') { $sql="INSERT INTO Online_Users (username, LoggedUser) VALUES ('$_GET[user]','$_GET[login]')"; $result = mysql_query($sql); if($result) { $qrytable1="SELECT username, LoggedUser FROM Online_Users WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "<p id='LoggedUser'>"; echo $row['LoggedUser'] . "</p>"; } } } elseif($username == 'all') { $names = implode(',',$insert); $result = mysql_query("SELECT * FROM Online_Users") or die('Error: ' . mysql_error()); $num_rows = mysql_num_rows($result); echo "There are $num_rows Users Online right now"; } } } ?> Hey in my edit page i have 2 radio buttons in my form and i need to make sure the same value is still selected how can i do that? thanks I have a form that contains radio buttons and when it is submitted the content of the form are added to a database. I was wondering how you get the values of radio boxes when submitting the form. I have the following radio buttons and when submitting I use "$_POST['article_type']" but this doesn't seem to work. Thanks for any help. <label>PDF Article</label><input name="article_type" value="pdf" type="radio" /> <label>Video Webcast</label><input name="article_type" value="webcast" type="radio" /> <label>Podcast</label><input name="article_type" value="podcast" type="radio" /> I am pulling records from a mysql db. Example Output: Team A= Our Team Team b = An opponent team Team A score = 7 Team B score = 8 Team A = Our Team Team b = Another Opponent Team A score = 3 Team B score = 1 What I need now is to add ONE more output, which is whether this is a "WIN" or a "LOSS". Should I add a field into the table that calc's this? If so, how? Please be specific. Or, should I use php to compare Team A score vs Team B score PER every record and then insert this new variable into the output. If so, how do I create a new variable value for every single output in the table? I know ultimately that this is a IF THEN type of calc, but can't quite figure out how specifically. Please be specific. Thanks Good evening, This has been bugging me for 24 hours now. I have created 2 web applications. The first one is the dummy, and the second one is the final. Basically, this two web applications does the same, just a few modifications made on the final one. I have a process of pulling out of information from the database should the user would want to modify a field. I have a problem though, the dummy one works perfectly, but the new one don't. In fact, if I use the dummy php file together with the new files, the dummy won't be working. But if I use it together with the old files, it works perfectly fine. This is the error I am getting: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\invent-asia\edit_client.php on line 46 <?php include("dbconnection.php"); if(isset($_POST["btnSubmit"])) { $id = $_POST["id"]; $territory = $_POST["territory"]; $job_title = $_POST["job_title"]; $area_of_work = $_POST["area_of_work"]; $employer = $_POST["employer"]; $location = $_POST["location"]; $job_title = $_POST["job_title"]; $date_posted = $_POST["date_posted"]; $closing_date = $_POST["closing_date"]; $department = $_POST["department"]; $gender = $_POST["gender"]; $first_name = $_POST["first_name"]; $last_name = $_POST["last_name"]; $title = $_POST["title"]; $telephone = $_POST["telephone"]; $address_1 = $_POST["address_1"]; $address_2 = $_POST["address_2"]; $address_3 = $_POST["address_3"]; $country = $_POST["country"]; $city = $_POST["city"]; $postal_code = $_POST["postal_code"]; $website = $_POST["website"]; $email_address = $_POST["email_address"]; $comment_by_cg = $_POST["comment_by_cg"]; $date_emailed = $_POST["date_emailed"]; $mailing_comments = $_POST["mailing_comments"]; $telesales_comments = $_POST["telesales_comments"]; $query = "UPDATE contacts SET territory= '".$territory."', job_title = '".$job_title."', area_of_work = '".$area_of_work."', employer = '".$employer."', location = '".$location."', job_title = '".$job_title."', employer = '".$employer."', date_posted = '".$date_posted."', department = '".$department."', closing_date = '".$closing_date."', gender = '".$gender."', first_name = '".$first_name."', last_name = '".$last_name."', title = '".$title."', telephone = '".$telephone."', address_1 = '".$address_1."', address_2 = '".$address_2."', address_3 = '".$address_3."', country = '".$country."', city = '".$city."', postal_code = '".$postal_code."', website = '".$website."', email_address = '".$email_address."', comment_by_cg = '".$comment_by_cg."', date_emailed = '".$date_emailed."', mailing_comments = '".$mailing_comments."', telesales_comments = '".$telesales_comments."' WHERE id = '".$id."'"; mysql_query($query) or die(mysql_error()); echo "<script> alert('You have successfully updated a record'); window.location = 'view.php'; </script>"; } $query = "SELECT * FROM contacts WHERE id = '".$_GET["id"]."'"; $result = mysql_query($query, $connection); if(mysql_num_rows($result) > 0) - THIS IS THE 46th LINE IN THE CODE { $territory = mysql_result($result,0, "territory"); $job_title = mysql_result($result, 0, "job_title"); $area_of_work = mysql_result($result, 0, "area_of_work"); $employer = mysql_result($result, 0, "employer"); $status = mysql_result($result, 0, "status"); $location = mysql_result($result,0, "location"); $department = mysql_result($result,0, "department"); $date_posted = mysql_result($result,0, "date_posted"); $closing_date = mysql_result($result,0, "closing_date"); $gender = mysql_result($result,0, "gender"); $first_name = mysql_result($result,0, "first_name"); $last_name = mysql_result($result,0, "last_name"); $title = mysql_result($result,0, "title"); $telephone = mysql_result($result,0, "telephone"); $address_1 = mysql_result($result,0, "address_1"); $address_2 = mysql_result($result,0, "address_2"); $address_3 = mysql_result($result,0, "address_3"); $city = mysql_result($result,0, "city"); $country = mysql_result($result,0, "country"); $postal_code = mysql_result($result,0, "postal_code"); $website = mysql_result($result,0, "website"); $email_address = mysql_result($result,0, "email_address"); $comment_by_cg = mysql_result($result,0, "comment_by_cg"); $date_emailed = mysql_result($result,0, "date_emailed"); $mailing_comments = mysql_result($result,0, "mailing_comments"); $telesales_comments = mysql_result($result,0, "telesales_comments"); } ?> Can anyone help me solve this issue? This is the only feature in my project that is left bugged Your quick response is well appreciated. Thank you very much FOr some reason i cant pull data from an XML file to insert into the database, it works without error just adds a blank value in the database? i have this code at the moment, i guess arrayValue[71] is the value i need to pull and add to the "TABLE2" table, but when i run the script it just adds a blank value in the database? <?php include "connect.php"; //Price check Isle 9001! Query EVE-Central API. Example XML file is: http://api.eve-central.com/api/marketstat?typeid=35®ionlimit=10000002 $queryItemList = mysql_query("SELECT * FROM TABLE2;") or die(mysql_error()); $rowCount = mysql_num_rows($queryItemList); $s=0; $typeArray = array(); $region = "regionlimit=10000002"; while($s<$rowCount){ $typeID = mysql_result($queryItemList,$s,"typeID"); echo $typeID."<br />"; //echo "start<br />"; $reader = new XMLReader(); //echo "initialized XMLReader<br />"; $url = "http://api.eve-central.com/api/marketstat?typeid=".$typeID; echo $url.$region."<br />"; $reader->open($url.'&'.$region); $t=0; $arrayName = array(); $arrayValue = array(); while ($reader->read()) { //echo $reader->name; $name = $reader->name; $arrayName[$t] = $name; if ($reader->hasValue) { //echo ": " . $reader->value."<br />"; $value = $reader->value; $arrayValue[$t] = $value; } $t++; } echo $arrayValue[71]; $import="UPDATE TABLE2 SET marketPrice='$arrayValue[71]' WHERE typeID='$typeID';"; mysql_query($import) or die(mysql_error()); $s++;; } print_r($typeArray); /*print_r($arrayName); echo "<br />"; echo "<br />"; echo "<br />"; print_r($arrayValue);*/ ?> an example XML file would be: Code: [Select] <!-- Automatically generated data from EVE-Central.com --> <!-- This is the new API :-) --> − <evec_api version="2.0" method="marketstat_xml"> − <marketstat> − <type id="24692"> − <all> <volume>4.00</volume> <avg>152500000.00</avg> <max>152500000.00</max> <min>152500000.00</min> <stddev>0.00</stddev> <median>152500000.00</median> <percentile>0.00</percentile> </all> − <buy> <volume>0.00</volume> <avg>0.00</avg> <max>0.00</max> <min>0.00</min> <stddev>0.00</stddev> <median>0.00</median> <percentile>0.00</percentile> </buy> − <sell> <volume>4.00</volume> <avg>152500000.00</avg> <max>152500000.00</max> <min>152500000.00</min> <stddev>0.00</stddev> <median>152500000.00</median> <percentile>152500000.00</percentile> </sell> </type> </marketstat> </evec_api> im looking at pulling the following value from the <sell> section: Code: [Select] <median>152500000.00</median> i am guessing the above should be arrayValue[71] but for some reason its not picking it up. any help on this would be greatly appreciated as im lost in this script. OK, I've scoured the forms on here, searched and tutorial read and even pulled out an old PHP book. Alas, I'm stumped. First off, my two tables that I'm trying to pull data from: rubric ------------------------------------- ---- code ---- | ---- title -------- ------------------------------------- ABCD | Category Name schedule ---------------------------------------------------- ------ name ------ | ------ short_title ------ ---------------------------------------------------- ABCD-123-4569 | Title Is Here Now, none of these share the same value, per say. rubric.code shares the first THREE letters from schedule.name, but that is all. What I'm trying to do is something similar to the old: A apple automobile B banana basket bench C car child crumb ... etc, etc, where the letter heading is actually the rubric.title value and then underneath it it lists all the matching short_title from schedule where the first four letters of schedule.name match the value of rubric.code - if that even makes sense. Unfortunately these are the tables I have to work with. If anyone out there has any ideas, I would be thrilled to hear them. Another thing that is driving me crazy is that this server I'm working on doesn't have error reporting turned on so I've been stuck with just a white screen to let me know something is amiss. I'm running PHP Version 5.3.3-7+squeeze8 if that helps. Thank you! I've got a table (tbl_items) that holds a number of items and the individual information for each. Within 'tbl_items' I also have a row labeled 'category_id' in which each item is given a number (ex: 2). I've got a separate table (tbl_items_categories) that only has 2 rows: 'category_id' and 'category_name'. I wasn't sure if a JOIN method would be best for this but what would be the best approach to list all items and within each item, also echo out the name of the category they belong to and not the category_id number? Hello,
I'm not sure if I'm allowed to post the code, as I didn't write it. But, if you could offer some ideas on where I'm going wrong, I'd be very appreciative!
I basically have a feature on my homepage that displays "Hello _username_!" upon login, but the username is missing. So, I'm presuming that the functionality for pulling the username from the table is somehow failing.
Any ideas?
Thanks
Daisy
Ok I have a fairly straight forward question. I am designing a baseball website and I am trying to add in a schedule, here is what I have: Data Bases 1) Teams DB - Each team has a unique team ID, location, logo, and owner 2) Schedule DB - Each game has a unique game ID, and the schedule is set up like this: AWAY = Team ID, HOME = Team ID.... So I assume I am using the JOIN command to pull the schedule from both databases, any idea how the SQL command would look? index.php?page=1 that link style but there is not hard files it is all to be stored in the DB here is what i have got so far Code: [Select] <? $result = mysql_query("SELECT * FROM page") or die(mysql_error()); $row = mysql_fetch_array( $result ); if(isset($_GET['page'])) { echo $row['text']; } else { $result = mysql_query("SELECT * FROM page WHERE id='1'") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo $row['text']; } ?> but always shows page ID 1 (home page) so i no i am missing something just not sure what hehe DB structu Code: [Select] menu ----id (auto increase) ----name (home, about etc) ----id2 (page weight) pages ----id (auto increase) ----name (page name home, about etc) ----text (page text) link structure from the menu Code: [Select] <? $result = mysql_query("SELECT * FROM menu ORDER BY id2") or die(mysql_error()); ?> <table> <? while($row = mysql_fetch_array( $result )) { ?> <tr><td> <a href="index.php?page=<? echo $row['id'];?>"><? echo $row['name']; ?></a> </td></tr> <? } ?> </table> dont think i have missed any info that i have on file but not sure why it will not link so thought of you guys hehe Thanx in advance Ok this is puzzleing. I am geting "Could not delete data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1". but its is deleting the entry that needs to be removed. The "1" is the entry. Just not sure what is causing the error. I do have another delete php but I have put that on the back burning for the time being.
<?php $con = mysqli_connect("localhost","user","password","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20 "); $amp20ptid = $_POST['amp20ptid']; // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); mysqli_query($con, "DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); if (!mysqli_query($con, $amp20ptid)); { die('Could not delete data: ' . mysqli_error($con)); } echo "Part has been deleted to the database!!!\n"; mysqli_close($con); } ?> Newbie here, I am actually a math teacher working on creating a simulated store front for my students where they keep up with inventory, budgeting etc. Everyday my students will have to look at how much product is in stock, how much product was sold, and then input how much should be ordered for the next day. I am working on an answer key that will be used to validate students input but the 'quantity' and 'sold' fields will be relative to the most recent post. Right now the code below pulls all the rows under 'quantity', but I need it to only pull the most recent post. I have done my best to search the forum and try to find how to do this, but admittedly I am not even really sure what to be searching for. Any help would be great. Code: [Select] <?php $con = mysql_connect("localhost","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("myDatabase", $con); $result = mysql_query("SELECT * FROM myTable"); while($row = mysql_fetch_array($result)) { $quantity = $row['quantity']; $sold = $row['numbersold']; $needed = $row['remaining']; echo $needed-($quantity-$sold); } mysql_close($con); ?> |