PHP - Problem With Arrays In Url Query
I tired something earlier, with no luck... so I'm taking a few steps back. I've been working this one complicated page for days...
Here's what used to work: Code: [Select] //the current URL $page_name = $_SERVER["REQUEST_URI"]; //remove any old limit from query before requesting a new limit $tmp = array(); foreach ($_GET as $fld => $val) if ($fld != 'limit') $tmp[] = $fld . '=' . $val; $page_name = $_SERVER['SCRIPT_NAME'] . '?' . implode('&',$tmp); //sets the number of records to be displayed on the page <form> <select name="link"> <option value="<? echo "$page_name" ?>&limit=25">25 records per page</option> <option value="<? echo "$page_name" ?>&limit=50">50 records per page</option> <option value="<? echo "$page_name" ?>&limit=100">100 records per page</option> </select> </form> This grabs the current URL, and clears the &limit= string before a new limit is introduced to avoid: www.example.com/test.php?sub=math[]&sub[]=science&limit=25&limit=50&limit=100 The problem, is that my URL is already querying an array: www.example.com/test.php?sub[]=math&sub[]=science So now, when I apply the form above to this URL set the new limit to 50 records per page the URL actually becomes: www.example.com/test.php?sub=Array&limit=50 Warning: Invalid argument supplied for foreach() ... on line 147 I guess I've broken the array? Code: [Select] //line 147 echo "subject:<BR />"; if(!empty($_GET['sub'])) foreach($_GET['sub'] as $sub) { echo "$sub <BR />\n"; } ~Wayne Similar TutorialsHi, I am trying to create a view where the user can sort by any column. What I have made so far works great, but when it comes to pagination, which I will be trying soon, I foresee a problem . The thing is, my code gets data out of a database and puts it into a multidimensional array, which is sorted using afew array sorting functions. It is a query that drives the main loop, and inside that loop are other queries that get various data from other tables, which is where the problem lies when coming to sort with pagination. What I would like to know is how would I build a myslq query that can accomplish the same thing as my code, but do away with the need for the arrays? My code is here, sorry about it being so long: <?PHP if($_POST['targetid']) { $box = array() ; if($_POST['type']) { $extra = 'AND entity_details.typeRef = ?' ; $targetType = $_POST['type'] ; } $sortMode = $_POST['sortmode'] ; $targetUser = $_POST['targetid'] ; include('pdoconnect.php') ; $result = $dbh->prepare("SELECT entity_details.name, entity_contacts.name AS cName, entity_contacts.id, entity_details.countryRef FROM entity_details, entity_contacts WHERE entity_contacts.isPrimary = 1 AND entity_contacts.entityRef = entity_details.id $extra AND entity_details.ownerRef = ?") ; if($extra) { $result->bindParam(1, $targetType, PDO::PARAM_INT) ; $result->bindParam(2, $targetUser, PDO::PARAM_INT) ; } else $result->bindParam(1, $targetUser, PDO::PARAM_INT) ; $result->execute() ; $count = $result->rowCount() ; if($count > 0) { echo "Showing " ; if($targetType == 2) echo "prospects!" ; elseif($targetType == 3) echo "customers!" ; elseif($targetType == 4) echo "leads!" ; else echo "everything." ; echo '<br />' ; } if($count > 0) { $mode = $_GET['sort'] ; echo "<div class='row'>\n" ; echo "<div class='cell'>" ; if($sortMode != 'name') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'name');\">Name</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrname');\">Name</a>" ; echo "</div>" ; echo "<div class='cell'>" ; if($sortMode != 'contact') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'contact');\">Contact</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrcontact');\">Contact</a>" ; echo "</div>" ; echo "<div class='cell'>" ; if($sortMode != 'email') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'email');\">Email</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rremail');\">Email</a>" ; echo "</div>" ; echo "<div class='cell'>" ; if($sortMode != 'tel') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'tel');\">Tel</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrtel');\">Tel</a>" ; echo "</div>" ; echo "<div class='cell'>" ; if($sortMode != 'payment') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'payment');\">Payment Terms</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrpayment');\">Payment Terms</a>" ; echo "</div>" ; echo "<div class='cell' style='width:30px;'>" ; if($sortMode != 'currency') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'currency');\">Cur</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrcurrency');\">Cur</a>" ; echo "</div>" ; echo "<div class='cell'>" ; if($sortMode != 'country') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'country');\">Country</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrcountry');\">Country</a>" ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; if($sortMode != 'lastc') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'lastc');\">Last Contacted</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrlastc');\">Last Contacted</a>" ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; if($sortMode != 'lastm') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'lastm');\">Last Marketed</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrlastm');\">Last Marketed</a>" ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; if($sortMode != 'lastd') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'lastd');\">Last Deal</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrlastd');\">Last Deal</a>" ; echo "</div>" ; echo "<div class='cell' style='width:50px;'>" ; if($sortMode != 'cltv') echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'cltv');\">CLTV</a>" ; else echo "<a onclick=\"traderSelectCustomer('$targetUser', '$targetType', 'Rrcltv');\">CLTV</a>" ; echo "</div>" ; echo "</div>\n" ; } else { echo "You have no " ; if($targetType == 2) echo "prospects!" ; elseif($targetType == 3) echo "customers!" ; elseif($targetType == 4) echo "leads!" ; else echo "nothing!" ; } while($row = $result->fetch(PDO::FETCH_ASSOC)) { $id = $row['id'] ; $countryid = $row['countryRef'] ; // Get primary contact data. $resultName = $dbh->prepare("SELECT entity_contacts_emails.email, entity_contacts_telephones.tel FROM entity_contacts_emails, entity_contacts_telephones WHERE entity_contacts_emails.contactRef = ? AND entity_contacts_telephones.contactRef = ? LIMIT 1") ; $resultName->bindParam(1, $id, PDO::PARAM_INT) ; $resultName->bindParam(2, $id, PDO::PARAM_INT) ; $resultName->execute() ; $rowName = $resultName->fetch(PDO::FETCH_ASSOC) ; /////////////////////////// // Get country. $resultCountry = $dbh->prepare("SELECT country FROM countries WHERE id = ? LIMIT 1") ; $resultCountry->bindParam(1, $countryid, PDO::PARAM_INT) ; $resultCountry->execute() ; $rowCountry = $resultCountry->fetchColumn() ; /////////////////////////// // Get currencies dealt with. $resultCurrencies = $dbh->prepare("SELECT currencies.symbol FROM entity_currencies_dealt, currencies WHERE entity_currencies_dealt.currencyRef = currencies.id AND entity_currencies_dealt.entityRef = ?") ; $resultCurrencies->bindParam(1, $id, PDO::PARAM_INT) ; $resultCurrencies->execute() ; while($rowCurrencies = $resultCurrencies->fetch(PDO::FETCH_ASSOC)) { $currencyString .= $rowCurrencies['symbol'] . " " ; } /////////////////////////// // Get payment terms. $resultTerms = $dbh->prepare("SELECT entity_payment_terms.term FROM entity_details, entity_payment_terms WHERE entity_details.paymentTermsRef = entity_payment_terms.id AND entity_details.id = ?") ; $resultTerms->bindParam(1, $id, PDO::PARAM_INT) ; $resultTerms->execute() ; $resultTerms = $resultTerms->fetchColumn() ; /////////////////////////// // Get last contacted. $resultLastCon = $dbh->prepare("SELECT DATE(date) FROM contact_method_history WHERE id = ? ORDER BY date LIMIT 1") ; $resultLastCon->bindParam(1, $id, PDO::PARAM_INT) ; $resultLastCon->execute() ; $resultLastCon = $resultLastCon->fetchColumn() ; /////////////////////////// // Get last enquired. $resultLastEnq = $dbh->prepare("SELECT DATE(dateCreated) FROM entity_enquiries WHERE entityRef = ? ORDER BY DATE(dateCreated) LIMIT 1") ; $resultLastEnq->bindParam(1, $id, PDO::PARAM_INT) ; $resultLastEnq->execute() ; $resultLastEnq = $resultLastEnq->fetchColumn() ; /////////////////////////// array_push($box, array(rawurldecode($row['name']), rawurldecode($row['cName']), $rowName['email'], $rowName['tel'], $resultTerms, trim($currencyString), $rowCountry, $resultLastCon, $resultLastEnq)) ; $currencyString = '' ; } } $i = 0 ; function subval_sort($a, $subkey, $mode) { foreach($a as $k=>$v) { $b[$k] = strtolower($v[$subkey]); } if(strstr($mode, 'Rr')) arsort($b); else asort($b); foreach($b as $key=>$val) { $c[] = $a[$key]; } return $c; } if($sortMode == 'name' || $sortMode == 'Rrname') $x = 0 ; if($sortMode == 'contact' || $sortMode == 'Rrcontact') $x = 1 ; if($sortMode == 'email' || $sortMode == 'Rremail') $x = 2 ; if($sortMode == 'tel' || $sortMode == 'Rrtel') $x = 3 ; if($sortMode == 'payment' || $sortMode == 'Rrpayment') $x = 4 ; if($sortMode == 'currency' || $sortMode == 'Rrcurrency') $x = 5 ; if($sortMode == 'country' || $sortMode == 'Rrcountry') $x = 6 ; if($sortMode == 'lastc' || $sortMode == 'Rrlastc') $x = 7 ; if($sortMode == 'laste' || $sortMode == 'Rrlaste') $x = 8 ; if($count > 0) $box = subval_sort($box, $x, $sortMode); foreach($box as $row) { echo "<div class='row'>\n" ; echo "<div class='cell'>" ; echo $row[0] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[1] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[2] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[3] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[4] ; echo "</div>" ; echo "<div class='cell' style='width:30px;'>" ; echo $row[5] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[6] ; echo "</div>" ; echo "<div class='cell'>" ; echo $row[7] ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; echo $row[8] ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; echo $row[9] ; echo "</div>" ; echo "<div class='cell' style='width:100px;'>" ; echo $row[10] ; echo "</div>" ; echo "<div class='cell' style='width:50px;'>" ; echo $row[11] ; echo "</div>" ; echo "</div>\n" ; } ?> I know maybe it can be done using many subqueries(?) but I am pretty average at MySQL. Can anyone tell me how? Given the following query,
SELECT t1.a, t1.b, t2.c FROM t1 INNER JOIN t2 ON t2.id=t1.t2_id WHERE t1.pk=123;I get the following three records: array( array('a'=>1,'b'=>2,'c'=>4), array('a'=>1,'b'=>2,'c'=>5), array('a'=>1,'b'=>2,'c'=>8) )What would be the best way to get just one record such as the following? array('a'=>1,'b'=>2, 'c'=>array(4,5,8))My thoughts were to use MySQL's GROUP_CONCAT, and then use implode() to turn it into an array, but didn't know if there was a better way. Thanks Here is my code snippets: <form name="form2" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <?php $i=1; while($i<=floor($_REQUEST['numpack'])) { ?> <table width="325" border="0" cellspacing="0" cellpadding="0" style="float: left;" class="aluminium"> <tr> <td align="center" rowspan="2"><span class="transparent" style="color: #FFF; font-weight: bold;"><?=$i; ?>.</span></td> <td align="center">L</td> <td align="center">x</td> <td align="center">W</td> <td align="center">x</td> <td align="center">H</td> </tr> <tr> <td align="center"><input name="length[]" type="text" size="4" maxlength="3" /></td> <td align="center">x</td> <td align="center"><input name="width[]" type="text" size="4" maxlength="3" /></td> <td align="center">x</td> <td align="center"><input name="height[]" type="text" size="4" maxlength="3" /></td> </tr> </table> <?php $i++; } ?> <input type="hidden" name="numarea" value="<?=$_REQUEST['numpack']; ?>" /> <input name="" type="submit" value="Submit" /> </form> The problem is getting the data from the array set in the above form... This is what I have and it comes back with errors: <?php } If (isset($_REQUEST['numarea'])) { echo $_REQUEST['numarea']; $vol=0; $i=1; while($i<=ceil($_REQUEST['numarea'])) { $volume[$i] = $_REQUEST['width'] * $_REQUEST['height'] * $_REQUEST['length']; echo $volume[$i]; $vol = $vol + $volume[$i]; $i++; } echo $vol; } ?> The echos are to put out the data when its calculated... Hey guys. I am creating an application that require dynamic fields generated by javascript. I have managed to create the forms the database and pretty much may things. I come to hit a roadblock with this array problem. I am trying to get the data from the browser by checking which one contain more than one value and then transverses through another array this one
$nyingi = [ 'location_' => ['text' => 'loc_txt','priority' => 'loc_order'], 'photo_' => ['path' => 'p_txt'], 'video_' => ['path' => 'v_txt'], 'product_' => ['p_id' => 'pt_q', 'text' => 'pt_txt', 'expire' => 'pt_xpr', 'title' => 'pt_tt'], 'service_' => ['p_id' => 'st_q', 'text' => 'st_txt', 'expire' => 'st_xpr', 'title' => 'st_tt'], 'hours_' => ['time1' => 't1', 'time2' => 't2', 'type' => 'tt'], 'map_' => ['text' => 'm_txt'] ]; I am very grateful for any input. I have a field in a database that contains references (pattern: authorYYYY), such as the following string:
"authorA1989; authorB1978a; authorB1984; authorC1999; authorC2000a; authorC2000b; authorC2002; authorD2009"
What I want is an output as the following in order to create a proper bibliography (therefore accessing another table and picking out the respective reference details):
authorA
1989
authorB
1978a
1984
authorC
1999
2000a
2000b
2002
authorD
2009
I somewhat fail to group the values (years) per author. I know that keys are unique, but is there a way to work around this?
Many thanks for any help!
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'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.
When I use this query $sql1="select * from fagudtryk_muskler where latinsk like \"$trimmed%\" order by latinsk UNION ALL select * from fagudtryk_knogler where latinsk like \"$trimmed%\" order by latinsk"; //-run the query against the mysql query function $result=mysql_query($sql1); //-count results $numrows=mysql_num_rows($result); I get this error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given How can I fix this? Hello everybody. I have a query-question... I have a form that writes data into the database. BUT... I want to verify that data if it allready exists. There are 3 fields that needs to be checked: 1. Type; <- if yes, check 2. 2. Coordinates1 (+ or - 2 from existing record) <- if yes check 3. If no: insert record and echo: "Mine posted succesfully in the database!" 3. Coordinates2 (+ or - 2 from existing record) <- if yes echo: "There is allready a mine of this type in the database on that location!". If no: insert record and echo: "Mine posted succesfully in the database!" (One coordinate uses this format: xxxxxx,yyy (Where xxxxxx is coordinates1 and yyy is coordinates2). A comparison for 1 variable I can find, but not for three and also not how to incorporate the + or - 2. Any help is greatly appreciated. Christiaan code I have so far: Code: [Select] <? include 'mining_cfg.php'; // html collect variable $type = $_POST['type']; $level = $_POST['level']; $coordinates1 = $_POST['coordinates1']; $coordinates2 = $_POST['coordinates2']; if ($type == ".$type") AND if ($coordinates1 == ".$coordinates1") AND if ($coordinates2 == ".$coordinates2"){ echo "Mine posted succesfully!"; } else { echo "There is allready a mine of this type in the database on that location!"; } // sql insert into database $sql ="INSERT INTO mining(type, level, coordinates1, coordinates2) VALUES ('".$type."', '".$level."', '".$coordinates1."', '".$coordinates2."')"; //uitvoeren van de query : if (!($temp = mysql_query($sql,$connection))) showerror(); header ( "Location: http://swr.infiniteserve.com/swr-site/test/post_mining.php" ); ?> Im just trying to get this query to retrieve one peice of data about a user if they are logged in however instead of producing any sort of mysql errors or anything it just stops the page from loading properly. Can anyone help solve this? here is my query code: $query = "SELECT credits FROM users WHERE username = $session->username"; $res = mysql_query($query) or die (mysql_error()); $row = mysql_fetch_assoc($res); $ans = $res['credits']; <form method="post" > <fieldset> <table> <tr> <td>naam van het gerecht:</td> <td><input type="text" name="nieuwgerecht" /></td> </tr> <tr> <td></td> <td></td> <td>ingredient 1:<input type="text" name="ingredient1" /></td> </tr> <tr> <td></td> <td></td> <td>ingredient 2:<input type="text" name="ingredient2" /></td> </tr> <tr> <td></td> <td></td> <td>ingredient 3:<input type="text" name="ingredient3" /></td> </tr> <tr> <td></td> <td></td> <td>ingredient 4:<input type="text" name="ingredient4" /></td> </tr> <tr> <td></td> <td></td> <td>ingredient 5:<input type="text" name="ingredient5" /></td> </tr> </table> <input type="submit" name="cmdvoegtoe" value="voeg toe" /> </fieldset> </form> <?php if(isset($_POST['cmdvoegtoe'])) { if (empty($_POST['ingredient1'])) { echo "<script>alert(\"ingredient nummer 1 moet zeker ingevuld zijn!\");</script>"; } else { $query="INSERT INTO tblgerecht VALUES(NULL, '$_POST[nieuwgerecht]')"; mysql_query($query, $connectie) or die('Error, insert query failed'); } } ?> Parse error: parse error in ... on line 118 problem with mysql query can someone help me with it Having some odd issues with a simple query :S. The first problem is that i have selected all records but it miss's out records in a pattern (the first, fifth, ninth and so on). The second issue is i am trying to select by ascending order but it's just not doing it. The QUERY Code: [Select] $comments = "SELECT * FROM $commentsTable LIMIT $start, $per_page "; $commentResults = mysql_query($comments); $commentRows = mysql_fetch_array($commentResults); The while loop displaying the records Code: [Select] <?php while($commentRows = mysql_fetch_array($commentResults)){?> <div id="comments"> <div id="CommentWrapper"> <div id="comment"> <div id="UserName"><? echo $commentRows['id']." "; ?><? echo $commentRows['name'];?></div> <div id="UserComment"><? echo $commentRows['comment'];?></div> <div id="UserEmail"><a href="<? echo $commentRows['email'];?>"><? echo $commentRows['email'];?></a></div> <div id="PostDateTime"><i>Posted: </i><? echo $commentRows['datatime'];?></div> </div> </div> </div> <?php } mysql_close(); ?> http://dvplus.webuda.com/oophptest/database.query.php <<< the project Hi all, Could someone have a look at the stuff below. I am able to show the $_POST variables, but from the moment i use mysqli_real_escape_string it goes wrong ( as in the variable seems empty) // mysqli connection file is above here // $clean_name = mysqli_real_escape_string(trim($_POST['name'])); $clean_email = mysqli_real_escape_string(trim($_POST['email'])); echo 'clean_name = '.$clean_name; //outputs noting echo 'clean_email = '.$clean_email; //outputs noting $query_control = "SELECT email FROM my_table WHERE email = $clean_email"; $result = mysqli_query($dbc, $query_control)or die(mysqli_error($con)); // <------- spotted: should have been $dbc //check for duplicates $number = mysqli_num_rows($result); echo $number; if($number === 0){ $output = 'valid'; }else{ $errormessage .= 'duplicate entry'; } } any help would be welcome edit- Oh i spotted some stuff (after changing it becamce: 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 '' at line 1) But not able to fix it really. im joining a table onto the query to show how many likes a post has but it is displaying the post x amount of times depending on how many likes there are. I think its something to do with the way im joining onto the pid of the post table: $post_query = $link->query("SELECT p.*, u.*, l.* FROM ".TBL_PREFIX."posts as p JOIN ".TBL_PREFIX."users as u ON (u.u_username = p.p_poster) LEFT JOIN ".TBL_PREFIX."post_likes as l ON (l.l_pid = p.p_pid) WHERE p_tid = '$tid' ORDER BY p.p_time_posted ASC")or die(print_link_error()); $likes = array(); while($post_info = $post_query->fetch()) { // SOF LIKE LIST if (count($post_info['l_pid']) >= 1) { $likes[] = $post_info['l_username']; $amount_likes = count($likes); $slice = array_slice($likes, 0, 4, true); $remain = array_slice($likes, 4, $amount_likes, true); $remain_num = count($remain); $like_list = ''; if($amount_likes > 4) { for($i=0; $i<=3; $i++) { $like_list .= profile_link($likes[$i]).', '; } $like_list .= 'and '.$remain_num.' other like this'; } elseif($amount_likes <= 3) { for($i=0; $i<3; $i++) { $like_list .= profile_link($likes[$i]).' '; } $like_list .= 'like this'; } } the likes are stored in their own database table seperate from the posts any advice? I have a running total that I am pulling from a database that I need to sort by year. I have tried adding WHERE YEAR(datepicker) = '2015' but keep getting an error. Here is the original query that works fine when I run it. Just don't need all the records.
SELECT id, datepicker, startmiles, endmiles, O.totalMiles, car, section, (select sum(totalMiles) FROM vehicle WHERE id <= O.id) 'runningTotal' FROM vehicle O ORDER BY datepicker DESC Hi Im just working on a wordpress pugin at the moment and Iw as trying out this piece of code $mylink = $wpdb->get_row("SELECT * FROM $wpdb->testtable WHERE id = 1"); echo $mylink->id ; there is data in the table there is an id equal to one but it not coming up with anything I tried it with anouther pable and it works fine I can for example $mylink = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE id = 1"); echo $mylink->post_content ; That comes up fine with the data But the first one I dont know why its not working can anyone help Thanks James Hi, my site is displaying something weird, http://86.21.243.231/ on the table at the bottom, it should list the amount of tickets sold. if the user deposits 0.3, then it should display 3 seperate rows for 0.1 with their payout address. but for 0.3, it displays 2 rows of 0.15 instead. the code for the table is: Code: [Select] $sql="SELECT * FROM tickets WHERE `round` = '$round' AND `confirmed` = 'yes' ORDER BY timestamp ASC"; $result=mysql_query($sql); $row=mysql_fetch_array($result); $result=mysql_query($sql); while($row = mysql_fetch_array( $result )) { $ticketamount = $row['amount']; $ticketspurchased = (int)($ticketamount / $ticketprice); $ticketamount = $ticketamount / $ticketspurchased; for ( $counter = 1; $counter <= $ticketspurchased; $counter += 1) { $i++; echo "<tr><td>"; echo $i; echo "</td><td>"; echo $row['address']; echo "</td><td>"; echo $ticketamount; echo "</td><td>"; echo $row['confirmed']; echo "</td><td>"; echo $row['timestamp']; echo "</td></tr>"; } } 0.5 shows correctly Any ideas? I have a table 'combo' with two fields, id and char.
I want to populate a table, with the following query which fails.
$sql = mysql_query("SELECT id,char FROM combo ORDER BY id DESC LIMIT 28");
I a bit rusty on sql but can't see what is wrong with this.
Can anyone help please.
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=348956.0 |