HuggieBear
Members-
Posts
1,899 -
Joined
-
Last visited
Everything posted by HuggieBear
-
Nine72, I'd use a bit of Ajax as already suggested, along with file(); What's the format of the file, is it comma separated or something? Regards Huggie
-
You obviously have a column in your database that's a unique field, probably auto-incrementing. Is that $record_id? If it is, then you will need to include that in the WHERE clause of your query. [code=php:0]$query = "SELECT * FROM audio WHERE record_id = '$record_id'";[/code] That should give you the correct track to stream. This is obviously part of a much larger piece of code, so I can't comment on the bits you posted underneath the SQL code. Regards Huggie
-
counting all records in tables containing 'windows_'
HuggieBear replied to 87dave87's topic in PHP Coding Help
[quote author=boo_lolly link=topic=124416.msg515491#msg515491 date=1170006562] [url=http://php.net/mysql_num_rows]mysql_num_rows()[/url]??? [/quote] Boo, that's not really appropriate in this situation. Regards Huggie -
[quote author=studgate link=topic=124316.msg515473#msg515473 date=1170003438] HuggieBear, I can't find where the WHERE clause was not set [/quote] Sorry, I didn't see it in the first post, even more reason to capitalise the syntax :) There doesn't seem to be any syntax errors so try this and let me know if you get an error messages... [code] <?php $dbconn = mysql_connect("localhost","user","passwordhere"); mysql_select_db("databasehere"); $strsql = "UPDATE tblreports SET `event_date`='$event_date', `event_time`='$event_time', `kb`='$kb', `event_duration`='$event_duration', `city`='$city', `state`='$state', `zip`='$zip', `foreign_country`='$foreign_country', `county`='$county', `nr_witness`='$nr_witness', `activity`='$activity', `location_type`='$location_type', `location_age`='$location_age', `description`='$description', `summary`='$summary', `characteristics`='$characteristics', `uname`='$uname', `uemail`='$uemail', `uaddress`='$uaddress', `ucity`='$ucity', `ustate`='$ustate', `uzip`='$uzip', `uphone`='$uphone', `uoccupation`='$uoccupation', `religy`='$religy', `education`='$education', `uage`='$uage', `ugender`='$ugender', `medication`='$medication', `medication_recent`='$medication_recent', `illness`='$illness', `drug`='$drug', `drug_recent`='$drug_recent', `alcohol`='$alcohol', `alcohol_recent`='$alcohol_recent', `anyuseof`='$anyuseof', `charlast`='$charlast' WHERE id='$editid'"; mysql_query($strsql) or die ("Unable to execute query:<br>$strsql<br>" . mysql_error()); list($nr_rows) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM tblreportsbyedate WHERE edate='$event_date';")); if (empty($nr_rows)) $strsql = "INSERT INTO tblreportsbyedate (`edate`,`nr`) VALUES('$event_date','1')"; else $strsql = "UPDATE tblreportsbyedate SET nr=nr WHERE edate='$event_date';"; mysql_query($strsql) or die ("Unable to execute query:<br>$strsql<br>" . mysql_error()); list($nr_rows) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM tblreportsbystate WHERE state='$state';")); if (empty($nr_rows)) $strsql = "INSERT INTO tblreportsbystate (`state`,`nr`) VALUES('$state','1')"; else $strsql = "UPDATE tblreportsbystate SET nr=nr WHERE state='$state';"; mysql_query($strsql) or die ("Unable to execute query:<br>$strsql<br>" . mysql_error()); list($nr_rows) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM tblreportsbyactivity WHERE activity='$activity';")); if (empty($nr_rows)) $strsql = "INSERT INTO tblreportsbyactivity (`activity`,`nr`) VALUES('$activity','1')"; else $strsql = "UPDATE tblreportsbyactivity SET nr=nr WHERE activity='$activity';"; mysql_query($strsql) or die ("Unable to execute query:<br>$strsql<br>" . mysql_error()); list($nr_rows) = mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM tblreportsbycity WHERE city='$city';")); if (empty($nr_rows)) $strsql = "INSERT INTO tblreportsbycity (`city`,`nr`) VALUES('$city','1')"; else $strsql = "UPDATE tblreportsbycity SET nr=nr WHERE city='$city';"; mysql_query($strsql) or die ("Unable to execute query:<br>$strsql<br>" . mysql_error()); mysql_close($dbconn); ?> [/code]
-
[quote author=nfr link=topic=124419.msg515462#msg515462 date=1170002320] SELECT * FROM stories WHERE (((category = '$news') and ((status != "pending") or (status != "rejected"))) order by article_id desc limit 2; Neil. [/quote] Shouldn't that be... [code]SELECT * FROM stories WHERE category = '$news' AND status != 'pending' AND status != 'rejected' ORDER BY article_id DESC LIMIT 2;[/code] I changed the OR code, I think that will return spurious results. Regards Huggie
-
counting all records in tables containing 'windows_'
HuggieBear replied to 87dave87's topic in PHP Coding Help
Shoz, That will work so long as the table type is that of MyISAM or ISAM. If it's InnoDB then it will only be an estimated row count. Regards Huggie -
Uploading an image using php to mysql database?
HuggieBear replied to PHPnewby!'s topic in PHP Coding Help
Dror, If you're going to post a solution then you should post it here. This is a community forum, we're here to help each other. If you're touting for paid work, then read the Freelance Forum. Especially as others like myself have taken their time to help you for free. Regards Huggie -
counting all records in tables containing 'windows_'
HuggieBear replied to 87dave87's topic in PHP Coding Help
This should also give you what you're after, and maybe slightly easier than what Shoz posted, but it does involve more queries. [code]<?php // This will give you a list of tables $sql = "SHOW TABLES LIKE 'windows_%'"; $result = mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); while ($table = mysql_fetch_array($result, MYSQL_NUM)){ $tables[] = $table[0]; // Put each table into an array } // Loop through the tables getting the totals for each foreach ($tables as $t){ $sql = "SELECT COUNT(*) FROM $t"; $result = mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); $total += mysql_result($result, 0); // add the count to the running total } // Echo the total posts echo $total; ?>[/code] Regards Huggie -
Uploading an image using php to mysql database?
HuggieBear replied to PHPnewby!'s topic in PHP Coding Help
It's actually very simple using php and there's plenty of tutorials about showing you hot to do it. Search the tutorials section on php freaks and also google. Regards Huggie -
Formatting this line correctly in fwrite function
HuggieBear replied to mattykewl's topic in PHP Coding Help
[quote author=kenrbnsn link=topic=124407.msg515420#msg515420 date=1169998350] Or you could use single quotes to delimit the string, then you don't have to escape the double quotes [/quote] Matty, What Ken said is very true, and probably in this situation the better way to go. Having said that, it is important you know how to escape special characters within strings. Regards Huggie -
Excellent, Don't forget to mark this thread as 'Solved'. Regards Huggie
-
Formatting this line correctly in fwrite function
HuggieBear replied to mattykewl's topic in PHP Coding Help
No problem, don't forget to mark the topic as 'SOLVED' Regards Huggie -
OK, when you insert into the database, use the now() function, as that will insert the current time, and when you retrieve data, use MySQL's [url=http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html]DATE_FORMAT()[/url] function... [code]<?php // Here's a query showing the now() function $sql = "INSERT INTO blogs (Title, File, Description, Time) VALUES ('$title', '$file', '$description', now())"; // Here's a query showing the date_format() function $sql2 = "SELECT Title, File, Description, DATE_FORMAT(Time, '%b %e, %Y') AS Time FROM blogs"; ?>[/code] Regards Huggie
-
Formatting this line correctly in fwrite function
HuggieBear replied to mattykewl's topic in PHP Coding Help
[code=php:0]<?php $xmlfile = fopen("squad.xml", "w"); fwrite($xmlfile,"<?xml version=\"1.0\"?>"); fclose($xmlfile); ?>[/code] This should work. Backslashes act as escape characters. Regards Huggie -
[quote author=thorpe link=topic=124402.msg515383#msg515383 date=1169991850] You need to make your 'time' field to be the type [i]timestamp[/i], this way you can order your results from newest to oldest. [/quote] Thorpe, will timestamp update automatically if you run an UPDATE statement on the row, for example if you were editing the post? This might not be ideal, hence I suggested a DATETIME field. Regards Huggie
-
[quote author=JayJ link=topic=124402.msg515380#msg515380 date=1169990866] I'm not sure exactly what you mean here. Do you mean I have to change something within my database? And like I mentioned my ['time'] is a VARCHAR. WOuld you recommend changing that to something else? [/quote] Where in your post did you mention that exactly :) Yes you need to change this column to DATETIME ideally. As for it not displaying anything, check the case, I notice you capitalised your column names, something I didn't, so try this: [code]<?php $sql = "SELECT * FROM blogs ORDER BY time DESC"; // notice the order by clause $result = mysql_query($sql) or die(mysql_error()); // This while loop is more effective and efficient than what you had while ($blog = mysql_fetch_array($result, MYSQL_ASSOC)){ // Display your blog here echo $blog['Title'] . "<br>\n"; echo $blog['File'] . "<br>\n"; echo $blog['Description'] . "<br>\n"; echo $blog['Time'] . "<br>\n"; } ?>[/code]
-
OK, let me give you a few pieces of advice before I tell you your problem... 1. Use [b][nobbc][code]...[/code][/nobbc][/b] tags around your code when posting in the forum as it looks a lot nicer and easy to read. 2. If you include <?php ?> tags in the code section you get syntax highlighting which is also a lot easier to read and also aids with spotting syntactically incorrect code. [code]<?php // Here's an example of what I mean by [code] tags and syntax highlighting $var = "variable"; if (isset($var)){ echo "You've set \$var to: " . $var; } ?>[/code] 3. Don't nest your functions, as it's more difficult to read and report errors. so avoid strings like this: [code]$num = mysql_num_rows(mysql_query("SELECT column FROM table_name"));[/code] in favour of: [code]$sql = "SELECT column FROM table_name"; $result = mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); $num = mysql_num_rows($result);[/code] 4. Use UPPER CASE for MySQL command syntax as it makes things a lot easier to read. So something like this: [code]SELECT column_name FROM table_name WHERE column_name = 'condition'[/code] This brings me onto solving your problem. You don't have a WHERE clause in your MySQL statement. Now this would have been a lot easier for me to spot if you'd capitalised your code :) Basically you need to be saying something along the lines of... [color=green][color=maroon]UPDATE[/color] tblreports [color=maroon]SET[/color] date_event = '$date_event' .... [b][color=maroon]WHERE[/color][/b] city = 'paris'[/color] If you don't define a WHERE clause, the code will try to update every row in the table. Regards Huggie[/code]
-
[SOLVED] 2 connections in the same script
HuggieBear replied to suzzane2020's topic in PHP Coding Help
You can make multiple connections to a MySQL server in the same script, but why would you want to? As for connecting to multiple databases, yes, you can do that to, make sure you use the optional link identifier with mysql_query(). Regards Huggie -
How can I disable php combobox's default option?
HuggieBear replied to toasty's topic in PHP Coding Help
Do you have this code live anywhere, so we can see what you mean? Regards Huggie -
Pulling Catagories or subcategories from a database
HuggieBear replied to rochdalemark's topic in PHP Coding Help
Is this the osCommerce code? If so, then it might be a good idea to ask this in either the third party forum here on PHP Freaks or the osCommerce forum, as you might be able to get a better response. Regards Huggie -
You need to use the time column to order the posts, it's best to do this in MySQL [code]<?php $sql = "SELECT * FROM blogs ORDER BY time DESC"; // notice the order by clause $result = mysql_query($sql) or die(mysql_error()); // This while loop is more effective and efficient than what you had while ($blog = mysql_fetch_array($result, MYSQL_ASSOC)){ // Display your blog here echo $blog['title'] . "<br>\n"; echo $blog['file'] . "<br>\n"; echo $blog['description'] . "<br>\n"; echo $blog['time'] . "<br>\n"; } ?>[/code] Regards Huggie
-
OK... Firstly, don't get the javascript to add a new field with an incremented name and number, get it to create a new field with the same name, so your form finishes up looking a little like this... [code]<input type="file" name="blogfile[]" id="blogfile[]"> <input type="file" name="blogfile[]" id="blogfile[]"> <input type="file" name="blogfile[]" id="blogfile[]"> <input type="submit" name="submit" id="submit" value="Post Blog">[/code] This way, when you get into php, the files will be in an array, as opposed to individual variables and it'll be a whole lot easier to loop through. I have to rush off now, but that should get you started and to get the id of the blog entry you'll want to use [url=http://uk.php.net/manual/en/function.mysql-insert-id.php]mysql_insert_id()[/url]. Look that up and I'll check back in about an hour as I have to go out now. Regards Huggie
-
Scott, Your problem is that you aren't setting the session variables anywhere. As soon as your user is confirmed as being logged in, you're redirecting them to their homepage. This code: [code]<?php if(count($user) > 0){ header('Location: '.$user['url']); } ?>[/code] Should look more like this: [code]<?php if(count($user) > 0){ $_SESSION['username'] = $user['username']; // This assigns the value to a session variable header('Location: '.$user['url']); } ?>[/code] Check your email ;) Regards Huggie
-
[SOLVED] Sorting dates (only DDMM) from the current day (DDMM)
HuggieBear replied to robr's topic in PHP Coding Help
[quote author=robr link=topic=123803.msg514695#msg514695 date=1169897999] I forgot to say that I was after a solution that does not worry about the year as I want to use dates before the UNIX 1970 date. [/quote] My solution only needs the current year, so that will never have been a problem, unless we have another 1970 ;) Huggie