PHP - Moved: Simplify Multiple Query?
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=315554.0 Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351561.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=305991.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330871.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=354981.0 I'm sure there must be a way to simplify code as it is taking forever. The code is for a form with the results emailed to me. I have attached the files as they are too big to post here Say I am running multiple contests at the same time. Each contest may have a different end date. One contest might run for a day, while the other one might run for 5 days. Below is the code done my way. I was wondering how you can improve it to make it more efficient? $current_date = date('Y-m-d H:i:s'); $find_contest = $db->prepare("SELECT days_count, date_started FROM contests WHERE status = :status"); $find_contest->bindValue(':status', 1); $find_contest->execute(); $result_contest = $find_contest->fetchAll(PDO::FETCH_ASSOC); if(count($result_contest) > 0) { foreach($result_contest as $row) { $days_count = $row['days_count']; // NUMBER OF DAYS THE CONTEST IS RUNNING $date_started = $row['date_started']; // START DATE FOR THE CONTEST $date_1 = DateTime::createFromFormat('Y-m-d H:i:s',$date_started); $date_1->modify('+1 day'); $end_date_1 = $date_1->format('Y-m-d H:i:s'); $date_2 = DateTime::createFromFormat('Y-m-d H:i:s',$date_started); $date_2->modify('+2 days'); $end_date_2 = $date_2->format('Y-m-d H:i:s'); $date_3 = DateTime::createFromFormat('Y-m-d H:i:s',$date_started); $date_3->modify('+3 days'); $end_date_3 = $date_3->format('Y-m-d H:i:s'); if($days_count == 1) { if($current_date > $end_date_1 AND $current_date < $end_date_2) { $day = 1; $end_date = $end_date_1; require 'run-contest.php'; } } else if($days_count == 2) { if($current_date > $end_date_1 AND $current_date < $end_date_2) { $day = 1; $end_date = $end_date_1; require 'run-contest.php'; } else if($current_date > $end_date_2 AND $current_date < $end_date_3) { $day = 2; $end_date = $end_date_2; require 'run-contest.php'; } else {} } else {} } }
Hi ? I wrote a PHP code but I think i can simplify more specially in the switch part , as you can see in the code. can you please give me some advise. <form method="post" action="<?=$_SERVER['PHP_SELF'];?>"> <fieldset> X: <input type="text" name="x" value="" /> <br/> Y: <input type="text" name="y" value="" /> <br/> <select name="diametre"> <option value=" "> </option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="6">6</option> <option value="8">8</option> <option value="10">10</option> <option value="12">12</option> <option value="14">14</option> <option value="16">16</option> <option value="18">18</option> <option value="20">20</option> <option value="22">22</option> <option value="24">24</option> <option value="26">26</option> </select> <input type="submit" value = "Calculer" /> </fieldset> </form> <?php if (isset($_POST["x"]) && isset($_POST["y"]) && isset($_POST["diametre"]) ){ $x = $_POST["x"]; $y = $_POST["y"]; $diametre = $_POST["diametre"]; } switch ($diametre) { case "2": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . " mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . " mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "3": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "4": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "6": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "8": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "10": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "12": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "14": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "16": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "18": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "20": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "22": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "24": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; case "26": $rayon = $diametre * 38.1; $dc = $x/2; $ad = ($y/2)-$rayon; $ac = sqrt(pow($ad,2) + pow($dc,2)); $ec = sqrt(pow($ac,2) - pow($rayon,2)); $LongueurBayonette = $ec*2; $alpha = asin($dc/$ac); $alpha = $alpha*180/M_PI; $beta = acos($rayon/$ac); $beta = $beta*180/M_PI; $angle = 180-$alpha-$beta; echo "X = " . $x . "mm" . "<br/>"; echo "Y = " . $y . "mm" . "<br/>"; echo "Longueur = " . number_format($LongueurBayonette,1) . "mm" . "<br/>"; echo "ꞵ = " . number_format($angle,1) . "°" . "<br/>"; echo "Rayon = " . $rayon . "mm" . "<br/>"; echo "⌀ = " . $diametre . '"' . "<br/>"; break; default: echo " "; } ?> The result is this page: http://cadtuts.eu/bayonette-test.php
Thank you ?
Hello! I have this approach on form validation(I'm just a newbie) Code: [Select] <?php if(isset($_POST['submit'])) { $proj_name = me_mysql_prep(trim($_POST['proj_name'])); $proj_content = me_mysql_prep($_POST['proj_content']); if(empty($_POST['proj_name'])) { $empty_name = array('Project Name Cannot Be Empty'); } if(empty($_POST['proj_content'])) { $empty_content = array('Content Cannot Be Empty'); } if(isset($empty_name) || isset($empty_content)); { $error_merge = array_merge($empty_name, $empty_content); } if(!empty($error_merge)) { foreach($error_merge as $error) { echo "<span class=\"error_validation\">*". $error . "<br></span>"; } } else { $query = "INSERT into rec_projects (proj_name, content, date_reg) VALUES('{$proj_name}', '{$proj_content}', '{$datenow}')"; $result = mysql_query($query,$connection); } echo "<br><br>"; } ?> My problem is at this line Code: [Select] <?php if(isset($empty_name) || isset($empty_content)); { $error_merge = array_merge($empty_name, $empty_content); } ?> because if, let's say $empty_name is not set, I'm going to have an error like Quote "undefined $empty_name" or something like that. I wonder if there's a PHP function that disregard a value in an array if it's not set.. or you guys have different approach to solve and simplify this?? these DB are on the same server sp inter query how do i combine the mysql_db()? Code: [Select] SELECT * FROM `sp.bookings` LEFT JOIN sp.bookings_items ON sp.bookings.id_item = sp.bookings_items.id LEFT JOIN inter.apartments ON inter.apartments.ID = sp.bookings_items.id_ref_external WHERE sp.bookings.the_date BETWEEN '$from_date' and '$to_date' and id_state=1 LIMIT 0 , 30 Hey, I have a query running inner joins... which currently works, but I need some more information pulled from other tables... Code: [Select] define('WPSC_TABLE_PRODUCT_LIST', "{$wp_table_prefix}wpsc_product_list"); define('WPSC_TABLE_PRODUCTMETA', "{$wp_table_prefix}wpsc_productmeta"); define('WPSC_TABLE_CATREF', "{$wp_table_prefix}wpsc_item_category_assoc"); define('WPSC_TABLE_CATNAME', "{$wp_table_prefix}wpsc_product_categories"); $cf="Linked Products"; $sku = get_post_meta($post->ID, $cf, true); $array = explode(",",$sku); $products = array_count_values($array); foreach($products as $key => $value) { $product = $wpdb->get_row("SELECT meta.product_id AS pid, list.name AS name, list.price AS price, retailer.category_id AS catid FROM ".WPSC_TABLE_PRODUCTMETA." AS meta INNER JOIN ".WPSC_TABLE_PRODUCT_LIST." AS list ON ( list.id = meta.product_id ) INNER JOIN ".WPSC_TABLE_SHOPNAME." AS retailer ON ( retailer.product_id = meta.product_id ) WHERE `meta_key` IN ( 'sku' ) AND `meta_value` IN ( '{$key}' ) ORDER BY list.id DESC"); ?> But I also need the category name - So I have to cross reference the following... wordpdem_wpsc_product_list id name 433 itemone 432 itemtwo 431 itemthree wordpdem_wpsc_item_category_assoc id product_id category_id 1 433 1 2 432 2 3 410 3 wordpdem_wpsc_product_categories id name 1 Bread 2 Fish 3 Snacks I've now written: Code: [Select] SELECT meta.product_id AS pid, list.name AS name, list.price AS price, retailer.category_id AS catid, category.name AS catname FROM wordpdem_wpsc_productmeta AS meta INNER JOIN wordpdem_wpsc_product_list AS list ON ( list.id = meta.product_id ) INNER JOIN wordpdem_wpsc_item_category_assoc AS retailer ON ( retailer.product_id = meta.product_id ) INNER JOIN `wordpdem_wpsc_product_categories``wordpdem_wpsc_product_list` AS category ON ( retailer.category_id = category.id ) WHERE `meta_key` IN ( 'sku' ) AND `meta_value` IN ( '{$key}' ) ORDER BY list.id DESC However it fails on line 12 (the Where statement...) Any ideas what I've done wrong? Hi guys I need your help, I am trying already for days to sort it out but does not work. My file "pback.php" displays the mysql table "sp_users". I want to add the columns "school_name" and "school_address" from another table "sp_schools" (same database) at the right end of the displayed table in "pback.php" (after the column update) I tried with leftjoin but it does not work. Please help me. I am getting really frustrated. Thank you... Code: [Select] <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="sp_users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY user_id"; $result=mysql_query($sql); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000000; } .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } --> </style> <title>User overview</title><table width="486" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600"> <tr> <td width="427"> <div align="left"> <table width="486" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users </strong></div></td> </tr> <tr> <td width="26" align="center"><span class="style2">id</span></td> <td width="70" align="center"><span class="style2">Name</span></td> <td width="114" align="center"><span class="style2">Lastname</span></td> <td width="146" align="center"><span class="style2">Email</span></td> <td width="88" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style10"><? echo $rows['user_id']; ?></span></td> <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_surname']; ?></span></td> <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td> </tr> <?php } ?> </table> </div></td> </tr> </table> <div align="left"> <p> </p> <p> </p> <p> </p> <p> <?php mysql_close(); ?> </p> </div> According to http://www.phpfreaks.com/forums/index.php?topic=350872.0: Is this a correct usage of what I am trying to create? Code: [Select] <?php $connect = mysql_connect("mysql12.000webhost.com","***","***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); $id = mysql_real_escape_string($_GET['id']); $extract = mysql_query("SELECT * FROM webclientcreate WHERE id='$id' LIMIT 1 WHERE ip='$ip' WHERE port='$port' WHERE name='$name' WHERE background='$background'"); ?> Code: [Select] <applet name=client width=765 height=503 archive='<?php echo $jars; ?>' code='client.class'> <PARAM name='java_arguments' value='-Xmx700m'> <PARAM name='server_name' value='<?php echo $name; ?>'> <PARAM name='detail' value='low'> <PARAM name='ip' value='<?php echo $ip; ?>'> <PARAM name='port' value='<?php echo $port; ?>'> <PARAM name='background_image' value='<?php echo $background; ?>'> <PARAM name='headicons' value=''> I've tried several types of the query line such as : Code: [Select] webclientcreate WHERE id='$id' LIMIT 1, WHERE ip='$ip', WHERE port='$port' Code: [Select] webclientcreate WHERE id='$id' LIMIT 1, ip='$ip', port='$port' Code: [Select] webclientcreate WHERE id='$id' LIMIT 1 ip='$ip' port='$port'Without any success I appreciate any help I can get! I can use the first while loop, but there is no data in the second while loop. Is there a better way as I have never done this before... Code: [Select] <?php $featured_results = mysql_query("SELECT * FROM products LEFT JOIN product_images ON products.product_id=product_images.product_id WHERE products.product_featured='1' AND products.product_active='1' AND thumb='1'"); $fa=0; while($featured_row = mysql_fetch_assoc($featured_results)) { $fthumb_result = mysql_query("SELECT image_name FROM product_images WHERE product_id='".$featured_row['product_id']."' AND thumb='1'"); $fthumb = mysql_fetch_row($fthumb_result); if ($fa==0) { echo "\n<img id=\"home-slider-photo-".$fa."\" class=\"home-slider-photo preload\" src=\"/includes/getimage.php?img=".$fthumb[0]."&w=370&h=370\" alt=\"\" />"; } else { echo "\n<img id=\"home-slider-photo-".$fa."\" class=\"home-slider-photo preload home-slider-photo-unsel\" src=\"/includes/getimage.php?img=".$fthumb[0]."&w=370&h=370\" alt=\"\" />"; } $fa++; } echo "<div id=\"home-slider-photo-price\">"; $fb=0; while($featured_row2 = mysql_fetch_assoc($featured_results)) { if ($fb==0) { echo "\n<div id=\"home-slider-photo-price-".$fb."\" class=\"home-slider-photo-price\">\n<span>only</span>$".$featured_row2['product_price']."\n</div>"; } else { echo "\n<div id=\"home-slider-photo-price-".$fb."\" class=\"home-slider-photo-price home-slider-photo-price-unsel\">\n<span>only</span>$".$featured_row2['product_price']."\n</div>"; } $fb++; } echo "</div>"; ?> Hi there, This is what I need to do, blow that is the code I have knocked up to do it but it doesn't seem to work. The main problem is the query that matches the atc callsigns to the pilots destinations.. can't fathom it myself. 1. Pull all the records from my database. 2. Assign their unique user id's, callsigns and destinations. 3. Execute a query in which you: SELECT * FROM CLIENTS WHERE (The 'clienttype' = 'ATC') AND match the callsign of the ATC users to the 'planned_destairport' of the 'clienttype' = 'PILOT'. For example if three people are going to Heathrow, then it would return 3 results. 4. Then do a mysql_num_rows of the result. 5. Lastly, execute a query that would update the 'atcarrivals' collumn in the database with the count number using the unique 'cid' as the identifier. All in a loop of course. // Selects all of the ATC Records. $atc_arrivals_selectquery = mysql_query ("SELECT * FROM CLIENTS"); // Starts the loop for fetching the records of the previous query. while($atc_arrivals_row = mysql_fetch_array($atc_arrivals_selectquery)){ // Sets the users cid, planned_destairport and callsign. $atc_cid = $atc_arrivals_row['cid']; $atc_destinations = $atc_arrivals_row['planned_destaiport']; $atc_callysign = $atc_arrivals_row['callsign']; // Searches the database and selects all records where the callsign is LIKE the destination airport. $atc_arrivals_check = mysql_query("SELECT * FROM CLIENTS WHERE clienttype = 'ATC' AND callsign LIKE '%$atc_destinations'"); // Counts previous query results. $atc_arrivals_count = mysql_num_rows($atc_arrivals_check); // Updates the atcarrivals column with the count.. $atc_arrivals_updatequery = mysql_query("UPDATE CLIENTS SET atcarrivals = '$atc_arrivals_count' WHERE cid = '$atc_cid' AND clienttype = 'ATC'"); // End loop. } Concerned columns are these: "cid" - Unique client id. "atcarrivals" - Number of arrivals from count. (This is the problem.) "planned_destairport" - Destination airport of pilot. Usually four letters long. IE. EGLL = Heathrow. Thanks. $query = mysql_query("SELECT COUNT(tickets.id),tickets.id,tickets.status,tickets.date,tickets.question,tickets.title,users.position FROM tickets,users WHERE tickets.id='$existing' users.username='$username'"); How do I get it so it selects data from the table tickets where id='$existing', but I also want to get a user's (who is viewing the ID) position (rank). $username is a session. So, any thoughts on how I would do so? My updated code: <?php session_start(); include("../includes/mysql.php"); include("../includes/config.php"); ?> <!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=iso-8859-1" /> <link href="../style.css" rel="stylesheet" type="text/css" /> <title><?php echo $title; ?></title> </head> <body> <div id="container"> <div id="content"> <div id="left"> <div class="menu"> <?php include("../includes/navigation.php"); ?> <div class="menufooter"></div> </div> <?php include("../includes/menu.php"); ?> </div> <div id="middle"> <?php $existing = $_POST['existing']; $ip = $_SERVER['REMOTE_ADDR']; $username = $_SESSION['user']; $query = mysql_query("SELECT COUNT(tickets.id),tickets.id,tickets.status,tickets.date,tickets.question,tickets.title,users.position FROM tickets,users WHERE tickets.id='$existing' OR users.username='$username'"); $get = mysql_fetch_assoc($query); if(!$existing) { echo ' <div class="post"> <div class="postheader"><h1>Error</h1></div> <div class="postcontent"> <p>You have not enetered in a ticket ID. Please go back and do so.</p> </div> <div class="postfooter"></div> </div> '; } elseif($get['COUNT(id)'] < 1) { echo ' <div class="post"> <div class="postheader"><h1>Error</h1></div> <div class="postcontent"> <p>The ticket ID you are trying to use doesnt exist. Please go back or submit another ticket.</p> </div> <div class="postfooter"></div> </div> '; } elseif($get['tickets.ip']==$ip || $get['user.position'] >= 1) { $status["tickets.status"]["0"] = "Waiting for support..."; $status["tickets.status"]["1"] = "Waiting for user..."; $status["tickets.status"]["2"] = "Ticket Closed..."; $status["tickets.status"]["3"] = "Ticket Opened..."; echo ' <div class="post"> <div class="postheader"><h1>View Ticket Status - ID '. $get["id"] .'</h1></div> <div class="postcontent"> <p>Title: '. $get["tickets.title"] .' - Posted on: '. $get["tickets.date"] .'</p> <p>Ticket Status: '. $status[$get["tickets.status"]] .'</p> <p>Question: '. nl2br($get["tickets.question"]) .'</p> </div> <div class="postfooter"></div> </div> '; } else { echo ' <div class="post"> <div class="postheader"><h1>Error</h1></div> <div class="postcontent"> <p>This is not your ticket. You only have permission to view your tickets. Please go back.</p> </div> <div class="postfooter"></div> </div> '; } ?> </div> </div> </div> </body> </html> mysql_query("UPDATE mods SET version='$version' AND name='$title' AND descritpion='$description' AND lastupdate='$date' WHERE id='$id'"); I don't think I'm doing it correctly. :/ Hello
We have a database table that confirms the installations started and completed for our game... and I am looking to confirm how many installs start but never complete...
So, this is my current query...
SELECT description, ip from error_log where description like '%install%' order by ip; Hi guys, I need your help! I have two tables "sp_users" and "sp_schools" in the same database. Now I want to add column "time" from "sp_schools" to a phpfile which displays "sp_users". The column "time" should be after column "update". I made it upto here, but to get the second query and display Please help. I am devastated... Code: [Select] <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxx"; // Database name $tbl_name="sp_users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY user_id"; $result=mysql_query($sql); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000033; } .style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #003333; } --> </style> <title>User overview</title><table width="486" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td width="427"> <div align="left"> <table width="486" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><div align="center" class="style1 style3"><strong>SchoolPorta Users </strong></div></td> </tr> <tr> <td width="26" align="center"><span class="style2">id</span></td> <td width="70" align="center"><span class="style2">Name</span></td> <td width="114" align="center"><span class="style2">Lastname</span></td> <td width="146" align="center"><span class="style2">Email</span></td> <td width="88" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style8"><? echo $rows['user_id']; ?></span></td> <td><span class="style8"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style8"><? echo $rows['user_surname']; ?></span></td> <td><span class="style8"><? echo $rows['user_login']; ?></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style8">update</a></td> </tr> <?php } ?> </table> </div></td> </tr> </table> <div align="center"> <?php mysql_close(); ?> </div> What I am trying to do is create a search box to search for a specific piece of information in my client database, say last name, or account number, invoice number, etc. is there a way i can use the keyword to match the query to multiple columns? here is my code, the script works if i use the $query to select just 1 column. but how do i add other columns to match it to? I know its where "different columns" LIKE search my problem is this line basically. Code: [Select] mysql_select_db("terra_elegante_operations", $con); $searchfor = $_GET['search_term']; $query = "select * from client_information where name_last like \"%$searchfor%\""; $result = mysql_query($query) or die("Couldn't execute query"); $row = mysql_fetch_array($result); echo $row['0']; Hi, I am currently working on a very detailed personal project during my vacation to keep me busy, but I have a problem, I am trying to create a unique id, without having the chance of a repetition of the id, even if its infinitely small. So I found the flickr ticket id system to be a good choice, since it was sequential and effective. My problem now is, how can I execute 2 queries simultaneously, given the hypothetical change that if I execute them with two separate queries (mysql_query), that there is the chance that another query could be executed in between the break, causing two id's to be the same. Since mysql_query can only execute a single query I am a bit stuck. I thought about possibly using CGI, but then again I have never used it, so I don't know its limitations. Can anyone suggestion anything to me for this problem, as to how I can execute two query strings in the same query. |