PHP - Moved: Php Query To Show Records That Starts With Number 555
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=325939.0 Similar TutorialsHi all, I am trying to use the Mysql COUNT function to count the number of records in a database where the manufacturer is the same and then generate a list of all manufacturers along with a number of associated records next to their name. I have got the script below to show the manufacturer in a fetch array but I can not get the number next to the manufacturer to work. A push in the right direction would be appreciated thanks. <?php include("cxn.php"); $query = "SELECT manufacturer FROM sales"; $result = mysqli_query($cxn,$query) or die(mysqli_error()); ?> <select name="manufacturer" id="manufacturer"> <option value="" selected="selected">Select a Manufacturer..</option>"; <?php while($row = mysqli_fetch_array($result)){ $query1 = "SELECT manufacturer COUNT(*) FROM sales WHERE manufacturer='$row[manufacturer]'"; // TRYING TO COUNT THE ROWS HERE $result1 = mysqli_query($cxn,$query1) or die (mysqli_error()); while($row1 = mysqli_fetch_array($result1)){ echo "<option value=\"202\">".$row['manufacturer'] ."[". $row1['COUNT(manufacturer)']."]</option>"; // SHOW NUMBER HERE } } ?> Hello guys, I have an website where I have 5 category blocks in my index page to show last 3 posts in each category. But I having problems showing the content in my "last added" block. Sometimes works, and sometimes not. Dont know what is happening... Look: http://screensnapr.com/e/Zm4ssA.jpg Only "Filmes" is showing, but not "Series"... the movies block sometimes have this issue too... the code is almost the same as above, maybe is the same problem... For each category that I want to show their posts, I have a file called newhome_x.php In my templates/dirvideo/main.tpl file, I have this code: Code: [Select] <div id="page_content" class="clearfix"> {info} {newhome_final} {content} </div> In my templates/dirvideo/newhome.tpl file, I have this code: Code: [Select] <li style="margin-right: 45px;" onclick="window.location='{link}'"> <a title='{home_title}' href="{link}"><img src="[xfvalue_poster]" alt='{home_title}' /></a> <h3 style="overflow:hidden"><a title='{home_title}' href="{link}">{home_title}</a></h3> </li> in my index.php I have this code: require_once ENGINE_DIR . '/modules/newhome.php'; require_once ENGINE_DIR . '/modules/newhome_b.php'; require_once ENGINE_DIR . '/modules/newhome_c.php'; require_once ENGINE_DIR . '/modules/newhome_d.php'; require_once ENGINE_DIR . '/modules/newhome_e.php'; if (clean_url ( $_SERVER['HTTP_HOST'] ) != clean_url ( $config['http_home_url'] )) { $replace_url = array (); $replace_url[0] = clean_url ( $config['http_home_url'] ); $replace_url[1] = clean_url ( $_SERVER['HTTP_HOST'] ); } else $replace_url = false; if (!$is_logged && !in_array($_GET['do'], array('register', 'lostpassword'))) { include 'index.html'; die; } $tpl->load_template ( 'main.tpl' ); $tpl->set ( '{lastusers}', $lastusers); $tpl->set('{forumStyle}', require_once ROOT_DIR . '/engine/bullet_energy/modules/load_style.php'); require_once ENGINE_DIR . '/modules/3news.php';$source = '<div class="index_top1" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " > <span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/movies.gif"> </span> <ul class="clearfix"> {newhome} </ul> </div> <div class="index_top2" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " > <span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/serie.gif"> </span> <ul class="clearfix"> {newhome_b} </ul> </div> <div class="index_top3" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " > <span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/music.gif"> </span> <ul class="clearfix"> {newhome_c} </ul> </div> <div class="index_top6" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " > <span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/jogo.gif"> </span> <ul class="clearfix"> {newhome_e} </ul> </div> <div class="index_top4" style="width: 100%; padding-top: 10px; padding-bottom: 10px; " > <span style="font-size: 24px; margin-left: 10px;"><img border="0" src="templates/dirvideo/images/programas.gif"> </span> <ul class="clearfix"> {newhome_d} </ul> </div>'; if (!isset($_REQUEST["catalog"]) && !isset($_REQUEST["newsid"]) && !isset($_REQUEST["do"]) && !isset($_REQUEST["page"]) && !isset($_REQUEST["category"]) && !isset($_REQUEST["cat"]) && !isset($_REQUEST["action"]) && !isset($_REQUEST["id"]) && !isset($_REQUEST["name"]) && !isset($_REQUEST["news_name"]) && !isset($_REQUEST["seourl"]) && !isset($_REQUEST["findpost"]) && !isset($_REQUEST["subaction"])) { $tpl->set ( '{newhome_final}', $source);} else { $tpl->set ( '{newhome_final}', "");} $tpl->set ( '{referer}', $referer_block ); $tpl->set ( '{calendar}', $tpl->result['calendar'] ); $tpl->set ( '{top_news}', $top_news ); $tpl->set ( '{last_news}', $last_news ); $tpl->set ( '{rand_news}', $rand_news ); $tpl->set ( '{archives}', $tpl->result['archive'] ); $tpl->set ( '{tags}', $tpl->result['tags_cloud'] ); $tpl->set ( '{vote}', $tpl->result['vote'] ); $tpl->set ( '{topnews}', $topnews ); $tpl->set ( '{login}', $tpl->result['login_panel'] ); $tpl->set ( '{info}', $tpl->result['info'] ); $tpl->set ( '{speedbar}', $tpl->result['speedbar'] ); $tpl->set ( '{catlist}', $catlist ); $tpl->set ( '{moviepopular}', $tpl->result['moviepopular'] );$tpl->set ( '{newhome}', $tpl->result['newhome'] );$tpl->set ( '{newhome_b}', $tpl->result['newhome_b'] );$tpl->set ( '{newhome_c}', $tpl->result['newhome_c'] );$tpl->set ( '{newhome_d}', $tpl->result['newhome_d'] );$tpl->set ( '{newhome_e}', $tpl->result['newhome_e'] ); In my engine/modules folder I have the files: newhome.php newhome_b.php newhome_c.php newhome_d.php newhome_e.php This is the code of engine/modules/newhome_c.php file (Series block): <?php if (!isset($_REQUEST["catalog"]) && !isset($_REQUEST["newsid"]) && !isset($_REQUEST["do"]) && !isset($_REQUEST["page"]) && !isset($_REQUEST["category"]) && !isset($_REQUEST["cat"]) && !isset($_REQUEST["action"]) && !isset($_REQUEST["id"]) && !isset($_REQUEST["name"]) && !isset($_REQUEST["news_name"]) && !isset($_REQUEST["seourl"]) && !isset($_REQUEST["findpost"]) && !isset($_REQUEST["subaction"])) { if( ! defined( 'DATALIFEENGINE' ) ) { die( "Hacking Attempt!" ); } $is_change = false; if ($config['allow_cache'] != "yes") { $config['allow_cache'] = "yes"; $is_change = true;} $tpl->result['newhome_c'] = dle_cache("newhome_c", $config['skin']); $tpl->load_template( 'newhome.tpl' ); if( strpos( $tpl->copy_template, "[xfvalue_" ) !== false ) { $xfound = true; $xfields = xfieldsload();} else $xfound = false; if ($tpl->result['newhome_c'] === false) { $sql = $db->query( "SELECT id, title, date, alt_name, category,xfields,autor FROM " . PREFIX . "_post WHERE category like '%7%' ORDER BY date DESC LIMIT 3" ); while ($row = $db->get_row($sql)) { $catchecks = explode(",",$row["category"]); $catpass = false; foreach ($catchecks as $catcheck) { if ($catcheck == "7") $catpass = true; } if ($catpass) { $sql2 = $db->query( "SELECT alt_name FROM " . PREFIX . "_category WHERE id='$row[category]'" ); $row2 = $db->get_row($sql2); if( $xfound ) { $xfieldsdata = xfieldsdataload( $row['xfields'] ); foreach ( $xfields as $value ) { $preg_safe_name = preg_quote( $value[0], "'" ); if( empty( $xfieldsdata[$value[0]] ) ) { $tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $tpl->copy_template ); } else { $tpl->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "\\1", $tpl->copy_template ); } $tpl->copy_template = str_replace( "[xfvalue_{$preg_safe_name}]", stripslashes( $xfieldsdata[$value[0]] ), $tpl->copy_template ); } } if($config['seo_type']=='1') { $link= "$row[id]".'-'."$row[alt_name]".'.html'; } else { $link="$row2[alt_name]".'/'."$row[id]".'-'."$row[alt_name]".'.html'; } $tpl->set( '{home_title}',stripslashes($row['title'])); $tpl->set( '{home_author}', stripslashes($row['autor'])); $tpl->set( '{home_date}', $row['date']); $tpl->set( '{link}',$link); $tpl->compile('newhome_c'); } } create_cache ("newhome_c", $tpl->result['newhome_c'], $config['skin']); $tpl->clear(); $db->free(); } if ($is_change) $config['allow_cache'] = false; } ?> I think that is everything here :-) Can please someone help me? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=311502.0 I have got this far that my code shows the list but say nothing starts with the letter 'y' then all of the 'x' and 'z' are grouped in the list. can anyone suggest a better way to have the list show correctly. the 'multiItemBoxes' css class is a rounded box that shows around each letter group. here is me code. Code: [Select] // $letters = array(); $letters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "; $L = 1; ?><div class="multiItemBoxes"><? // place first part of DIV. $previousLetter = "/"; // set previousLetter to the letter before '0' zero. used as a dummy string. while($results = mysql_fetch_assoc($getResults)) { if ($previousLetter == "/") { ?><strong style="font-size: 15pt;"><? echo(strtoupper($results['productTitle'][0])); ?></strong><br /><? } if (strtoupper($results['productTitle'][0]) == $letters[$L]) { ?></div><? // this is the ending of the DIV. If needed. ?><br class="clearfloat" /> <? if (strtoupper($results['productTitle'][0]) != " ") { ?><div class="multiItemBoxes"><strong style="font-size: 15pt;"><? echo(strtoupper($results['productTitle'][0])); ?></strong><br /><? $L++; } // this is the extra DIV start if not at end of DB list. } ?><a href="<? echo("cart.php?query=" . $results['Pid']); ?><? echo("&"); ?>i=y"><? echo(htmlspecialchars($results['productTitle'])); ?></a><br /><? $previousLetter = $results['productTitle'][0]; } // end of while ?></div><br class="clearfloat" /><? // This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=306153.0 I need help with a count query and displaying it. Right now have the following query $query = "SELECT COUNT(*) as num1 FROM spoiler WHERE id='$id"; $total_trophies = mysql_fetch_array(mysql_query($query)); $total_trophies = $total_trophies[num1]; So I have another query that pulls how many trophies there are. That way I can do the following ? echo $total_trophies; echo 'of'; echo $row[trophy_count]; ?> But the problem is sometimes in my database I could have mulitple entrys per trophy. For Trophy 1 I might have only one record so It counts it correctly for trophy 2 I could have 3 records so It counts each one of those records when I only one to count it once for that trophy How do you do this? Thanks in advance. I've got query. still shows all records in the database... any idea how i go about this? Code: [Select] $date= date('y-m-d'); $query=mysql_query("SELECT * FROM listing WHERE date >= $date") or die (mysql_error()); When I run this query to exclude records where id = $userarray['id'], $q = "SELECT * FROM users WHERE inst_id = '". $userarray['inst_id'] ."' AND id != '". $userarray['id'] ."' "; it actually ONLY returns records with $userarray['id'] as opposed to excluding them. Isn't the way to exclude them to use != ? Hi all, I'm trying to make a query that allows the user to edit the name of a entry in SQL. I believe I have the corect Syntax but I'm not sure if I have the code set up correctly. I am using 2 queries when I think it is possible with one. The first query is used to Pint out results for a certain year and the second to update the names. Code: [Select] $desiredYear = $_POST['year']; $nameEdit = $_POST['edit']; $origName = $_POST['orig']; echo ' The year you have chosen is '.$desiredYear; $describeQuery = "SELECT ID, Name, (SELECT SUM(SalesVolume) as SalesVolume FROM MonthlySales WHERE ProductCode=Products.ID AND Year = '$desiredYear') AS num_sales FROM Products"; $editQuery = "UPDATE Products SET Name = '$nameEdit' WHERE Name ='$origName'"; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Name</th><th bgcolor = "LightBlue" >ID</th> <th bgcolor = "LightBlue" >Sales</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['Name'].'</td>'; echo '<td>' .$row['ID'].'</td>'; echo '<td>' .$row['num_sales'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); Can somebody help me with this? Thank you Hello just wondering if someone can help me... I have a select multiple form that sends the id numbers of records I want to get... how do I construct the query to the mysql db to do this? $array-$_POST['form-array'] so something like $r = ("SELECT column from 'Table' WHERE ID = (array, values, here)") Thanks for any help. Have a web page that displays a number of update forms depending on the amout of records that get returned from a mysql query, if query returns 4 records then the page will display 4 identical forms, the trouble i'm having is getting the each of the 4 forms to display a different record as at the moment they all show just first record of query. I have played around with loops but not getting anywhere which may be due to my limited knowledge code for page is below Code: [Select] <?php $numberofrow =mysql_num_rows($Recordset1); for($counter = 1;$counter<=$numberofrow;$counter++){ ?> <label for="hometeam2"></label> <form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <label for="hometeam"></label> <input name="fixid" type="text" id="fixid" value="<?php echo $row_Recordset1['FixtureID']; ?>" /> <input name="hometeam" type="text" id="hometeam2" value="<?php echo $row_Recordset1['hometeamname']; ?>" /> <label for="homescore"></label> <input name="homescore" type="text" id="homescore" value="<?php echo $row_Recordset1['homescore']; ?>" /> <label for="awayscore"></label> <label for="fixid"></label> <input name="awayscore" type="text" id="awayscore" value="<?php echo $row_Recordset1['awayscore']; ?>" /> <label for="awayteam"></label> <input name="awayteam" type="text" id="awayteam" value="<?php echo $row_Recordset1['awayteamname']; ?>" /> <input type="submit" name="update" id="update" value="Submit" /> <input type="hidden" name="MM_update" value="form1" /> Hi ive been stuck for a while now and i just cant get my head around it so if you could help i'd be well chuffed. I'm trying to update multple rows in a table depending upon the results of another. I have a form that enables me to update a table called fleet. Another table called ships is realted to the fleet table as each ship is in a fleet: fleet ----- Fleetname* Location Detected ships ------ ShipID* Fleetname * Shipname The particular fleet i am editing is parsed as a url parameter. I made a query to search for all the ships that are in the fleet i am editing: Code: [Select] $colname_ShipsInfleet = "-1"; if (isset($_GET['recordID'])) { $colname_ShipsInfleet = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_ShipsInfleet = sprintf("SELECT * FROM ships WHERE FleetName = %s", GetSQLValueString($colname_ShipsInfleet, "text")); $ShipsInfleet = mysql_query($query_ShipsInfleet, $swb) or die(mysql_error()); $row_ShipsInfleet = mysql_fetch_assoc($ShipsInfleet); $totalRows_ShipsInfleet = mysql_num_rows($ShipsInfleet); It searched the ships WHERE the FleetName (which is the primary key of the fleet table) is parsed as a url parameter. The appropriate ship records that are generated i want to use so a field can be updated. For example im updating a fleet record and and setting the location (Planet Name) to a different value. I want the Ship records that are of that particular fleet to update a field (PlanetName) in ship table when the fleet table is updated. Code: [Select] if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE ships WHERE ShipID = $row_ShipsInfleet['ShipID'] SET PlanetName=%s", GetSQLValueString($_POST['select'], "text")); mysql_select_db($database_swb, $swb); $Result1 = mysql_query($updateSQL, $swb) or die(mysql_error()); $updateSQL = sprintf("UPDATE fleet SET PlanetName=%s, Detected=%s, Faction=%s WHERE FleetName=%s", GetSQLValueString($_POST['select'], "text"), GetSQLValueString(isset($_POST['checkbox']) ? "true" : "", "defined","1","0"), GetSQLValueString($_POST['hiddenField2'], "int"), GetSQLValueString($_POST['hiddenField'], "text")); mysql_select_db($database_swb, $swb); $Result1 = mysql_query($updateSQL, $swb) or die(mysql_error()); I'm really not sure how to proceed here so please if you can help me out that would be ace. Thank You This topic has been abducted by aliens, probed, and dropped off in JavaScript Help http://www.phpfreaks.com/forums/index.php?topic=359251.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=355218.0 Hi everyone, I have the task of building a PHP page where users can enter or remove as many records as they like into different categories. This then makes the number of records entered unknown, and therefore it becomes more complicated. To make this clearer, I have attached an image of what I am trying to do. Two questions: - Before submitting the form, how can each record entry be matched with the correct category? (maybe hidden form fields somehow?) - What is the best way of inserting each record (and it's associated category) into a MySQL database table from a single form submit? I want to try and keep this as simple as possible as the data will later be updated, removed etc. I'm experiencing a brain fart and just cannot picture the best way of going about this Any help and advice is much appreciated! Thanks in advance. Code: [Select] Basic table schema example... CATEGORY TABLE ---------------------------- | catid | category | ---------------------------- | 1 | Category A | | 2 | Category B | etc. etc. ---------------------------- DATA ENTRY TABLE ---------------------------- dataid | catid | data | -------------------------------- | 1 | 2 | data xyz | | 2 | 1 | data zyx | etc. etc etc. -------------------------------- This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356136.0 |