PHP - Moved: Select Records In Table 1 Based On Criteria From Tabel 2
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=308916.0 Similar TutorialsHi, I have db field with date. I want to make select statement with where clause when part of the date (month) is true. Example, i have records from 2020-2-1 until 2020-4-3, i want to select records for march only 2020-3-1 to 2020-3-31. how to do that? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356136.0 Hey, have used a long time on this... i hope you guys can help me :D - im new in the php / mysql world. so here it is: i want to make a list on my first page that post links (list.php) list.php works fine, i get a list of links from my database, and when i click on it it goes to test.com/klub.php?id= (and the id for the tabel) fx. test.com/klub.php?id=000000018. so i think the problem is in my klub.php, here i want to select * from siteinfo1 where id = the same id as i get from clicking the link on the other site :D xD... and then post the infomation for the 'name' of the link i clicked :D well here is my code :D i think the problem is $result = mysql_query("SELECT * FROM siteinfo1 WHERE id='$id'"); for if i change the id=$id to id=000000018 it post the info for the table whit that id nr... but then i cant see all the other info i need form 000000019 and so on :D xD i hope you understand my stupidity and know how to fix my problem :D thanks... _________________________________________ list.php _________________________________________ $result1 = mysql_query("SELECT * FROM siteinfo1") or die (mysql_error()); while($row1 = mysql_fetch_array($result1)) { echo "<A href=\"klub.php?id={$row1['id']}\">{$row1['navn']}</A>"; echo "</br>"; } _________________________________________ klub.php _________________________________________ $result = mysql_query("SELECT * FROM siteinfo1 WHERE id='$id'"); while($row = mysql_fetch_array($result)) { echo "$row[id]"; echo "</br>"; echo "Navn: "; echo "$row[navn]"; echo "</br>"; } Hi, I have a DB with two tables, customers and orders. One customer may have many orders, What I want to do is do a select on the two tables and get the customer info once, and then all the orders associated with the account. I saw how to do this once before using a join and then having to use a PHP foreach to break it up. I am just not sure of how to put the two together to make it work, or maybe there is an easier way completely. Any help is appreciated. Thanks B Example: Bob Smith Shoes Coat Boots Gloves Sally Jones Hat Purse Boots Umbrella This is posting to any row in mssql that has a matching 'start_date'. I would like it to post rows where start_date = '$start_date' and it also matches the 'meter_id' . It should perform this check of both parameters before posting to mssql.
<?php $session_id = $_SESSION['id']; $comm_id = $_GET['meter_id']; $start_date = $_GET['start_date']; $payment_date = $_POST['payment_date']; $amount_paid = $_POST['amount_paid']; $check_number = $_POST['check_number']; $sql = "UPDATE [radiogates].[dbo].[ops_invoice_history] SET payment_date = '$payment_date', amount_paid = '$amount_paid', check_number = '$check_number' where start_date = '$start_date'"; $query = sqlsrv_query($conn, $sql);Thank you for any help. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=354366.0 I am working on a project that involves providing details for county government, and if applicable, cities independent of county oversight. Virginia is a state with a lot of independent cities, so I wanted to echo them in a separate list underneath the county governments.
This code works fine when displaying Virginia information. However, I would like to hide the Independent Cities heading in every other state. For some reason, this code still echoes the Independent Cities heading in states without independant cities in the database.
Any thoughts or wisdom?
(sorry for pasting the whole bulky code)
$query = "SELECT * FROM state WHERE st_id=$statecode"; $result = mysql_query($query) or die("Query $query failed : " . mysql_error()); $row = mysql_fetch_assoc($result); $state_name=$row["st_name"]; $state_note=$row["state_notes"]; echo "<h2>Counties of " . $state_name; "</h2>\n"; $query = "SELECT * FROM counties WHERE st_id=$statecode AND visible=1 ORDER BY county_name ASC"; $result = mysql_query($query) or die("Query $query failed : " . mysql_error()); echo "<table width=100%><tr><td valign=top width=33%>\n"; $count = 1; $col = 0; $rowcount = (int)(mysql_num_rows($result) / 3) + 1; $remainder = mysql_num_rows($result) - ($rowcount - 1) * 3; /* ********************************************************* */ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href=\"services.php?county=".$row["county_id"]."\">".$row["county_name"] . "</style></a><br />\n"; $count = $count + 1; if ((($remainder > 0) && ($count == ($rowcount + 1))) || (($remainder <= 0) && ($count == $rowcount))) { $col = $col + 1; if ($col!=3) { echo "</td><td valign=top width=33%>\n"; $count = 1; if ($remainder > 0) $remainder = $remainder - 1; } } } /* ********************************************************* */ echo "</td></tr></table><br>\n"; mysql_free_result($result); /* ********************************************************* */ $query2 = "SELECT * FROM cities WHERE st_id=$statecode AND visible=1 ORDER BY city_name ASC"; $result2= mysql_query($query2) or die("Query $query failed : " . mysql_error()); $city_id = $row['city_id']; $city_name = $row['city_name']; if ($city_id!="") { echo "<h3>Independent cities of " . $state_name; "</h3>\n"; echo "<table width=100%><tr><td valign=top width=33%>\n"; $count2 = 1; $col2 = 0; $rowcount2 = (int)(mysql_num_rows($result2) / 3) + 1; $remainder2 = mysql_num_rows($result2) - ($rowcount2 - 1) * 3; /* ********************************************************* */ while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "<a href=\"services.php?county=".$row["city_id"]."\">".$row["city_name"] . "</style></a><br />\n"; $count2 = $count2 + 1; if ((($remainder2 > 0) && ($count2 == ($rowcount2 + 1))) || (($remainder2 <= 0) && ($count2 == $rowcount2))) { $col2 = $col2 + 1; if ($col2!=3) { echo "</td><td valign=top width=33%>\n"; $count2 = 1; if ($remainder2 > 0) $remainder2 = $remainder2 - 1; } } } /* ********************************************************* */ echo "</td></tr></table><br>\n"; mysql_free_result($result2); /* ********************************************************* */ } ?> Edited by myotch, 06 September 2014 - 09:19 PM. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321906.0 Hi,
I am a bit of a MYSQL newbie so please bear with me. I have a database created about football/soccer stats. The database at the moment contains the following tables but more maybe added:
Players
Clubs
Seasons
Competitions
I will create php pages for these tables that add, edit and delete records for each. But the problem I can't get my head around is how to add a record that uses data from other tables, for example we would add a...
player -> club-season-competition
Lets say we want create a player called 'Joe Bloggs' and want to add his details, we need somehow for the page to display an option for club, season and competition. Maybe they can be drop down boxes but how does one fill those drop down boxes with records that are already added in the database for each table?
Thanks
Hi. Im searching for a way to enter multiple records at once to mysql databased on a date range. Lets say i want to insert from date 2010-11-23 to date 2010-11-25 a textbox with some info and the outcome could look in database like below. ---------------------------------------------------------- | ID | date | name | amount | ----------------------------------------------------------- | 1 | 2010-11-23 | Jhon | 1 | | 2 | 2010-11-24 | Jhon | 1 | | 2 | 2010-11-25 | Jhon | 1 | ----------------------------------------------------------- The reason i need the insertion to be like this is because if quering by month and by user to see vacation days then vacations that start in one month and end in another month can be summed by one month. If its in one record then it will pop up in both months. Help is really welcome. Hello: I am trying to select all the records from a table, and display them. Having an issue... This is the code: Code: [Select] <ul> <?php $query = mysql_query("SELECT id,mySectionTitle FROM myWebSiteData"); while($menuData = mysql_fetch_array($query)) { <li><a href="a_websiteData.php?id=" .echo $menuData['id'] ."">echo $menuData['mySectionTitle']</a></li> } ?> </ul> This is the error: Code: [Select] Parse error: syntax error, unexpected '<' in /html/admin/a_websiteData.php on line 91 line 91 is the one that starts with "<li>" What am I missing, or what would be the best way to do this? This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=323045.0 Hello, Please excuse me if this sounds like a bit of a newb question. If I have a link to a users profile and use GET to pull information about that user from various tables using something like this: Code: [Select] <?php { $id = $_GET['id']; $user = mysql_query("SELECT * FROM users,tbl1,tbl2,tbl3,tbl4,tbl5 WHERE $id=tbl1.user_id AND tbl1.user_id=tbl2.user_id AND tbl2.user_id=tbl3.user_id ANDtbl3.user_id=tbl4.user_id AND tbl4.user_id=tbl5.user_id"); $user=mysql_fetch_assoc($user); } ?> <h3>Table 1</H3> <?php echo "<b>".$user['tbl1_title']."<br>"; ?><br /> <h3>Table 2</H3> <?php echo "<b>".$user['tbl2_title']."<br>"; ?><br /> <h3>Table 3</H3> <?php echo "<b>".$user['tbl3_title']."<br>"; ?><br /> <h3>Table 4</H3> <?php echo "<b>".$user['tbl4_title']."<br>"; ?><br /> <h3>Table 5</H3> <?php echo "<b>".$user['tbl5_title']."<br>"; ?><br /> Why does it only show the 1st record for that user from each table? And mostly, how do I change it to show all or a certain number of records from each table? Any help would be greatly appreciated. Thanks in advance This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=355218.0 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=309981.0 Hi all, I am having difficulty getting my UPDATE script to work. Basically the info is being pulled from a form and then being UPDATED, but it doesn't actually update and I am presented with no errors. It finds the record correctly and displays in the fields in the form as it should, just no update! Any ideas? Thanks in advance... Code: [Select] <?php error_reporting (E_ALL ^ E_NOTICE); $usr = "fdgdg"; $pwd = "dgdg"; $db = "dgdg"; $host = "dgdg.ddg.dg.50dgdg /***********************Get Record***********************/ $ref = (!empty($_GET['ref']))?trim($_GET['ref']):""; # connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid){ echo("ERROR: " . mysql_error() . "\n"); } $db_selected = mysql_select_db(database, $cid); $query = sprintf("SELECT * FROM fleet where fleetref like '%s' LIMIT 1","%".mysql_real_escape_string($ref)."%"); $result = mysql_query($query) or die($query."<br>".mysql_error()); $record = mysql_fetch_assoc($result); if(mysql_num_rows($result) > 0) { echo "<strong>Updating fleet vehicle</strong>"; $fleetref=$record["ref"]; $fleetmake=$record["fleetmake"]; $fleetmodel=$record["fleetmodel"]; $fleetberth=$record["fleetberth"]; $fleetyear=$record["fleetyear"]; $fleetlength=$record["fleetlength"]; $fleetchassis=$record["fleetchassis"]; $fleetengine=$record["fleetengine"]; $fleetlayout=$record["fleetlayout"]; $fleettype=$record["fleettype"]; $fleetcomments=$record["fleetcomments"]; $pricelow=$record["pricelow"]; $pricemid=$record["pricemid"]; $pricehigh=$record["pricehigh"]; $fleetof=$record["fleetof"]; }else{ echo "<div id=\"pages\"><strong>Record not found</strong> - Edit Directory</div>"; $fleetmake=""; $fleetmodel=""; $fleetberth=""; $fleetyear=""; $fleetlength=""; $fleetchassis=""; $fleetengine=""; $fleetlayout=""; $fleettype=""; $fleetcomments=""; $pricelow=""; $pricemid=""; $pricehigh=""; $fleetof=$record["fleetof"]; } if ($fleetof == $account) { /***********************Save Record***********************/ # this is processed when the form is submitted # back on to this page (POST METHOD) if (isset($_POST['submit'])){ $fleetmake=$_POST["fleetmake"]; $fleetmodel=$_POST["fleetmodel"]; $fleetberth=$_POST["fleetberth"]; $fleetyear=$_POST["fleetyear"]; $fleetchassis=$_POST["fleetchassis"]; $fleetengine=$_POST["fleetengine"]; $fleetlayout=$_POST["fleetlayout"]; $fleetlength=$_POST["fleetlength"]; $fleettype=$_POST["fleettype"]; $fleetcomments=$_POST["fleetcomments"]; $pricelow=$_POST["pricelow"]; $pricemid=$_POST["pricemid"]; $pricehigh=$_POST["pricehigh"]; # setup SQL statement $query = sprintf("UPDATE `fleet` SET `fleetmake` = '%s',`fleetmodel` = '%s',`fleetberth` = '%s',`fleetyear` = '%s',`fleetchassis` = '%s',`fleetengine` = '%s',`fleetlayout` = '%s',`fleetlength` = '%s',`fleettype` = '%s',`fleetcomments` = '%s',`pricelow` = '%s',`pricemid` = '%s',`pricehigh` = '%s' WHERE `fleetref` ='%s' LIMIT 1", mysql_real_escape_string($fleetmake),mysql_real_escape_string($fleetmodel),mysql_real_escape_string($fleetberth),mysql_real_escape_string($fleetyear),mysql_real_escape_string($fleetchassis),mysql_real_escape_string($fleetengine),mysql_real_escape_string($fleetlayout),mysql_real_escape_string($fleetlength),mysql_real_escape_string($fleettype),mysql_real_escape_string($fleetcomments),mysql_real_escape_string($pricelow),mysql_real_escape_string($pricemid),mysql_real_escape_string($pricehigh),mysql_real_escape_string($fleetref)); #execute SQL statement $result = mysql_db_query($db,$query,$cid) or die($query."<br>".mysql_error()); # check for error if (!$result){ echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo "<P>Fleet vehicle updated</P>\n"; } } else {echo "Sorry, you are not authorised to edit this vehicle, please contact the system administrator for further help.";} ?> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=311502.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=325939.0 Hi all. I built an online finance tracking thingy for myself and I got it to work using the following database table and PHP code. I didn't write the PHP code, rather, I edited it to suit my needs. It works great for my needs. I have a way to enter records and view the last 180 records in a table. The thing is, while viewing the table, I would lke to be able to edit and delete records. I don't know enough to be able to do this. Can it be done? I realize my PHP code would probably, for the most part, be totally different. Thanks for any help with this. Here is my DB table structu Code: [Select] DROP TABLE IF EXISTS `money`; CREATE TABLE IF NOT EXISTS `money` ( `id` int(5) NOT NULL AUTO_INCREMENT, `date` date NOT NULL, `type` varchar(18) NOT NULL, `checking` decimal(5,2) NOT NULL DEFAULT '0.00', `cash` decimal(5,2) NOT NULL DEFAULT '0.00', `description` varchar(25) NOT NULL, `who` varchar(25) NOT NULL, `note` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; And here is the PHP: Code: [Select] <?php $result = mysql_query ('SELECT date, type, checking, cash, who, description, note' . ' FROM money' . ' ORDER BY date DESC LIMIT 0,180') or die(mysql_error()); echo "<table border='1' cellpadding='5'>"; echo "<tr><th>Date</th><th>Type</th><th>Checking</th><th>Cash</th><th>Who?</th><th>Description</th><th>Note</th></tr>"; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['date']; echo "</td><td>"; echo $row['type']; echo "</td><td>"; echo $row['checking']; echo "</td><td>"; echo $row['cash']; echo "</td><td>"; echo $row['who']; echo "</td><td>"; echo $row['description']; echo "</td><td>"; echo $row['note']; echo "</td></tr>"; } echo "</table>"; ?> |