Jump to content

gizmola

Administrators
  • Posts

    5,959
  • Joined

  • Last visited

  • Days Won

    146

Everything posted by gizmola

  1. [!--quoteo(post=367324:date=Apr 21 2006, 02:22 PM:name=feri_soft)--][div class=\'quotetop\']QUOTE(feri_soft @ Apr 21 2006, 02:22 PM) [snapback]367324[/snapback][/div][div class=\'quotemain\'][!--quotec--] S o i must add this i n my query ?? ;) [/quote] Barand was as clear as he could be. MySQL Date columns have no Time component. If you need a Date + time in one column then you need to use a MySQL DateTime column. You can easily alter your table structure using ALTER TABLE to modify your DATE column to a DATETIME. If you're still confused try reading this: [a href=\"http://www.gizmola.com/blog/archives/51-Exploring-Mysql-CURDATE-and-NOW.-The-same-but-different..html\" target=\"_blank\"]http://www.gizmola.com/blog/archives/51-Ex...different..html[/a]
  2. gizmola

    help

    [!--quoteo(post=367326:date=Apr 21 2006, 02:27 PM:name=HostFreak)--][div class=\'quotetop\']QUOTE(HostFreak @ Apr 21 2006, 02:27 PM) [snapback]367326[/snapback][/div][div class=\'quotemain\'][!--quotec--] What im trying to do is be able to select the agent name which is $username from the table users but have its value be the id_num. Here is what Im doing: [code] $query = "SELECT id_num FROM users WHERE userlevel = '8'";   $result = mysql_query($query); print "<SELECT name=id_num><option>Choose One</option>"; while ($row = mysql_fetch_array($result))     {         extract($row);         echo  "<option value='$id_num'>$id_num</option>";     }     mysql_close($link); print "</SELECT>"; [/code] Im not sure how to exactly call the $username. Last time i tried it, it listed the username logged in for all the options. I guess because i didn't call it as a line or something. [/quote] First off, you can query more than one column in a single query, right? Try this code instead: [code] $query = "SELECT id_num, username FROM users WHERE userlevel = '8'";   $result = mysql_query($query); print "<SELECT name=id_num><option>Choose One</option>"; while ($row = mysql_fetch_assoc($result))     {         echo  "<option value='{$row['id_num']}'>{$row['username']}</option>";     }     mysql_close($link); print "</SELECT>"; [/code]
  3. [!--quoteo(post=367328:date=Apr 21 2006, 02:35 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Apr 21 2006, 02:35 PM) [snapback]367328[/snapback][/div][div class=\'quotemain\'][!--quotec--] Just some structure advice (maybe it's already built into mysql?) I have an address book table. Instead of using a freeform title field, I am using an integer field that records the keyfield from a titles table. When the people in the address book are displayed, I just convert the title's integer into the description recorded in the title's table. [code]$result=mysql_query("SELECT * FROM `contacts`"); $title_result=mysql_query("SELECT * FROM `titles`"); while($title_rows=mysql_fetch_assoc($title_result)) {    $title[$title_rows['keyfield']]=$title_rows['value']; } while($my_contact=mysql_fetch_assoc($result)) {    echo "Name: ".$my_contact['name'];    echo "<br>\n";    echo "Title: ".$title[$my_contact['title']];    echo "<br><br>\n"; }[/code] The title table also has a sort-by field -- which is what I want to sort the contacts results by. This would allow the "president" of a company to show up first, and his/her "assistant" to show up later on. I've been hacking on it for a few hours -- but I just can't figure out how to accomplish this without writing some kind of bubble sort. Any ideas would be greatly appreciated. Thanks! [/quote] You are going about this all wrong. Relational databases by their nature can join tables together. Remember that the result of a query is always a "result set" aka a table. Rather than using 2 seperate queries and trying to bind them together, you can simply join them in one query and use ORDER BY to order the result set in the way you want it to be. For example, experiment with phpMyAdmin and try something like: [code] SELECT contacts.*, titles.* FROM contacts, titles WHERE titles.title_id = contacts.contact_id ORDER BY title [/code]
  4. [!--quoteo(post=367325:date=Apr 21 2006, 02:22 PM:name=businessman332211)--][div class=\'quotetop\']QUOTE(businessman332211 @ Apr 21 2006, 02:22 PM) [snapback]367325[/snapback][/div][div class=\'quotemain\'][!--quotec--] right. Instead of msaccess since it's bad what other "program" do I need to start building databases on my computer to upload. And if I use a program to build a database, is that hand coding databases, I wanted to hand code everything, does using the program take the easy way out, and write and the sql for you, I am severely confused here. [/quote] This is a problem I see neophytes struggling with frequently. Interactive websites are almost universally driven by a database. Relational databases (Sybase, SQL Server, Oracle, DB2, MySQL, Postgresql) are typically preferred for their combination of power, speed and performance. SQL is the language you use to talk to a relational database, either to create tables, query information, or add/update/delete rows. Spend some time learning about relational databases. MySQL is very frequently used in the open source world, and commonly discussed on this forum. This website and the forum are built on top of LAMP (linux, apache, mysql, php). If you don't develope a good understanding and competency with relational databases, you will have a tough road ahead of you in regards to building interactive websites.
  5. [!--quoteo(post=367126:date=Apr 21 2006, 01:25 AM:name=jeephp)--][div class=\'quotetop\']QUOTE(jeephp @ Apr 21 2006, 01:25 AM) [snapback]367126[/snapback][/div][div class=\'quotemain\'][!--quotec--] Hello Friends, We are using [b][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]PHP and MySQL technologies[!--colorc--][/span][!--/colorc--][/b]in site running on [b][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]Linux[!--colorc--][/span][!--/colorc--][/b]. We are using PHP mail function to send emails to our site users on different occasion unfortunately we found that mail could not delivered on [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]AOL IDs[!--colorc--][/span][!--/colorc--] so all our site users who has AOL email ID are not able to receive any email those we have sent through PHP mail function. Expecting some assistance to get this resolved Regards, Paresh Kharsan [/quote] Well this is a complicated issue. By default PHP mail() simply tries to make an smtp connection to the destination mail server. This can cause many problems with mail servers that have aggressive spam prevention techniques, if for example, the server running the php script doesn't have a valid reverse DNS entry. The other problem is that if for whatever reason the original mail is rejected, there's really no record of that, since mail() isn't an MTA with any storage. The alternatives are either to build a mail queueing system using some sort of persistent storage (usually a database) or to have the mail handed off to an email server that has been configured to forward (relay) the mail on the php server's behalf.
  6. [!--quoteo(post=367123:date=Apr 21 2006, 12:35 AM:name=glennn.php)--][div class=\'quotetop\']QUOTE(glennn.php @ Apr 21 2006, 12:35 AM) [snapback]367123[/snapback][/div][div class=\'quotemain\'][!--quotec--] ok, here goes: [code]$sql = "SELECT CustomField1, CustomField2 , CustomField15, CustomField16 FROM oemp_members WHERE CustomField2 LIKE 'n%' OR CustomField15 LIKE 'n%' ORDER BY CustomField2 ASC"; $result = mysql_query($sql) or die("Query failed"); $lines = mysql_num_rows ( $result ); for ( $i=0;$i<$lines;$i++ ) {     $row = mysql_fetch_array($result);     print "<a href=\"http://${row[3]}\">${row[0]} ${row[1]}</a><br>"; }[/code] [/quote] Based on your description this is an either/or situation. First suggestion: use mysql_fetch_assoc(). Then you get a simple associative array keyed by column name. Right after this fetch check your condition: [code] if  (!empty($row['CustomField15'])) {   $url = $row['CustomField15']; } else {   $url = $row['CustomField1'].... etc.; } [/code] As I don't fully understand what would be in CustomField1 that would make you want to concat it with CustomField2, i'll leave off here, and if there's something else that I"m missing, feel free to provide more detail.
  7. [!--quoteo(post=367124:date=Apr 21 2006, 12:58 AM:name=freddykhalid)--][div class=\'quotetop\']QUOTE(freddykhalid @ Apr 21 2006, 12:58 AM) [snapback]367124[/snapback][/div][div class=\'quotemain\'][!--quotec--] Hey guys, I am having a problem getting the textfields for both the Login and the Password Fields the same width. Using Firefox, I have no problem. But using IE, it can be clearly seen that the Password field is shorter than the Login field. Here is my code: [/quote] How about trying size= for both inputs.
  8. [!--quoteo(post=367114:date=Apr 20 2006, 11:20 PM:name=HaZaRd420)--][div class=\'quotetop\']QUOTE(HaZaRd420 @ Apr 20 2006, 11:20 PM) [snapback]367114[/snapback][/div][div class=\'quotemain\'][!--quotec--] Hey man, that worked, but now when i go to edit it, the subject just dissapears and doesnt insert it. :( [/quote] Yes, notice the typo you made in the name of your form element for subject. Anytime something "sorta" works, you need to check for those types of errors.
  9. [!--quoteo(post=367050:date=Apr 20 2006, 05:11 PM:name=melvnatic)--][div class=\'quotetop\']QUOTE(melvnatic @ Apr 20 2006, 05:11 PM) [snapback]367050[/snapback][/div][div class=\'quotemain\'][!--quotec--] How do you make it so that a variable can be accessed from two different scripts? Let's say you set a variable in script #1, and you want to access that variable in script #2 in the same directory as script #1. How do you do that? [/quote] You have a variety of ways to persist variables. They are in no particular order: -pass as either url params or form variables -store them in a cookie -store them session variables -write them to a database, read them out -write to a file/read out -write to berkely db/ read out --- etc other IO options -Use the shared memory extension to write to a shared memory variables using shmop functions With databases, there's obviously a whole array of options there.
  10. [!--quoteo(post=367111:date=Apr 20 2006, 10:46 PM:name=HaZaRd420)--][div class=\'quotetop\']QUOTE(HaZaRd420 @ Apr 20 2006, 10:46 PM) [snapback]367111[/snapback][/div][div class=\'quotemain\'][!--quotec--] Ok Heres the problem, I got to edit it, click the link, I edit the textarea, i click submit, and nothing happends. Its suppose to use the echo "Thank you! Information updated" When i click the submit button but it doesnt, it just goes back to the link to edit again. Please Help me. [code] <?    if ($_POST["$submit"])    {       $subject = $_POST["subject"];         $content = $_POST["content"];         $author = $_POST["author"];             $date = $_POST["date"];              $sql = "UPDATE news SET subject='$subject',content='$content',author='$author', date='$date' WHERE id=$id";       //replace news with your table name above       $result = mysql_query($sql);       echo "Thank you! Information updated.";     } } ?> [/code] [/quote] My first question is... does this work at all? And if so, is that because you have register globals turned on? The reason I ask is because you look to see if $cmd isset, but you don't assign that variable. If you have register globals on, well you shouldn't, and the use ofthe $_GET and $_POST superglobs is very confusing. Pick an approach and stay with it. Probably this line explains part of your problem: [code] if ($_POST["$submit"]) [/code] $submit isn't what you want to index $_POST by. probably you meant 'submit' as you used it previously. However, it's obvious from your code, that what you want is an if - else situation based on the value of submit, which you check at the top of the block, so you probably should just rewrite your code to go with the implicit if- else condition. [code] if (!isset($_POST["submit"]))    {       $id = $_GET["id"];       $sql = "SELECT * FROM news WHERE id=$id";       $result = mysql_query($sql);               $myrow = mysql_fetch_array($result);       ?>              <form action="edit.php" method="post">       <input type=hidden name="id" value="<?php echo $myrow["id"] ?>">          Subject:<INPUT TYPE="subject" NAME="suject" VALUE="<?php echo $myrow["subject"] ?>" SIZE=30><br>       Content:<TEXTAREA NAME="content" ROWS=10 COLS=30><? echo $myrow["content"] ?></TEXTAREA><br>       Author:<INPUT TYPE="author" NAME="author" VALUE="<?php echo $myrow["author"] ?>" SIZE=30><br>             Date:<INPUT TYPE="date" NAME="date" VALUE="<?php echo $myrow["date"] ?>" SIZE=30><br>          <input type="hidden" name="cmd" value="edit">          <input type="submit" name="submit" value="submit">          </form>    <? } else  {       $subject = $_POST["subject"];         $content = $_POST["content"];         $author = $_POST["author"];             $date = $_POST["date"];              $sql = "UPDATE news SET subject='$subject',content='$content',author='$author', date='$date' WHERE id=$id";       //replace news with your table name above       $result = mysql_query($sql);       echo "Thank you! Information updated.";     } } [/code]
  11. [!--quoteo(post=367099:date=Apr 20 2006, 10:03 PM:name=freshrod)--][div class=\'quotetop\']QUOTE(freshrod @ Apr 20 2006, 10:03 PM) [snapback]367099[/snapback][/div][div class=\'quotemain\'][!--quotec--] I posted before, but I managed to figure out that problem... kind of. Now I have a related, yet entirely new and exciting problem. Here's the deal. I query the DB like so: $query = "SELECT jobName, jobPay, jobDescription FROM jobs WHERE numAbil <= {$abilities} ORDER BY jobName ASC"; I slap it into an array like so: while ($row = @ mysql_fetch_row($result)) { print "\n<tr>"; foreach ($row as $data) print "\n\t<td><center> {$data} </center></td>"; print "\n\t<td><input type=\"radio\" name=\"job\" value=\"{$data[0]}\"></td>"; print "\n</tr>"; } What I'm trying to do here is get the jobName from the query to be the value for the radio button. If you need more code or better description, please ask. Thanks. [/quote] My best guess is that you aren't accounting for the nature of mysql_fetch_row which returns a mixed array of indexed keys and associative keys, combined with the fact that you foreach this into a string, and then attempt to treat it like an array -- which is fine, but what you get is an array of characters, hence your one character output. But more than that, there's really no benefit to the obfuscation or the foreach, since you know exactly what columns you want to use, and where. I'd recommend you use instead mysql_fetch_assoc(). Your code would then be something like: [code] while ($row = mysql_fetch_assoc($result)) {      print "\n<tr>";          print "\n\t<td><center> {$row['jobName']} </center></td>";     print "\n\t<td><input type=\"radio\" name=\"job\" value=\"{$row['jobName']}\"></td>";     print "\n</tr>"; }         [/code]
  12. [!--quoteo(post=367094:date=Apr 20 2006, 09:31 PM:name=mmosel)--][div class=\'quotetop\']QUOTE(mmosel @ Apr 20 2006, 09:31 PM) [snapback]367094[/snapback][/div][div class=\'quotemain\'][!--quotec--] It's strange, when I send an email via mail() in php (hosted on my local server), the time of the email get's stamped an hour ahead of my computer's time. When I send email via my email client, the time stamp is correct. Odd. The only thing I can think of is that it's not accounting for the daylight savings time shift. Anyone know about this? [/quote] Sounds like a pretty reasonable assumption, especially if it's exactly one hour difference. Of course without OS info, there's very little else anyone can offer in aid.
  13. [!--quoteo(post=366231:date=Apr 18 2006, 03:56 PM:name=Vids)--][div class=\'quotetop\']QUOTE(Vids @ Apr 18 2006, 03:56 PM) [snapback]366231[/snapback][/div][div class=\'quotemain\'][!--quotec--] [code] <form method="get" action="http://www.rcsb.org/pdb/downloadFile.do?fileFormat=pdb&compression=NO&structureId=$_GET['id']"> <input type=text name=id value=""> <input type=submit value="Download"> </form> [/code] I have a problem. In the above form, When some one types the value in the text, and clicks on download, i want the browser to go to the following site [a href=\"http://www.rcsb.org/pdb/downloadFile.do?fileFormat=pdb&compression=NO&structureId=$id\" target=\"_blank\"]http://www.rcsb.org/pdb/downloadFile.do?fi...tureId=$id[/a] where $_GET['id'] is what they typed in. For Example, If they type in 1LYN, The browser must download [a href=\"http://www.rcsb.org/pdb/downloadFile.do?fileFormat=pdb&compression=NO&structureId=1LYN\" target=\"_blank\"]http://www.rcsb.org/pdb/downloadFile.do?fi...tructureId=1LYN[/a] Only the end of the URL changes. Whats wrong with my code? Any help will be appreciated! [/quote] Well you didn't actually provide any php code ;) YOu might try this: [code] <form method="get" action="http://www.rcsb.org/pdb/downloadFile.do?fileFormat=pdb&compression=NO&structureId=<?php echo $_GET['id']; ?>"> <input type=text name=id value=""> <input type=submit value="Download"> </form> [/code]
  14. [!--quoteo(post=367057:date=Apr 20 2006, 05:42 PM:name=Derek CC)--][div class=\'quotetop\']QUOTE(Derek CC @ Apr 20 2006, 05:42 PM) [snapback]367057[/snapback][/div][div class=\'quotemain\'][!--quotec--] hey i have a site i would like to have a login database and such but first i want to make just a php script that you can add or subtract varibles and still have it work for a register form Like for Name Email Birthday .ect and have it sent to a .txt file or email any help with that?? [/quote] You can have a form embedded in an html page that does other things. In other words, this is a common aspect of html. What drives the form processing is the target of the form if/when it's submitted.
  15. [!--quoteo(post=361788:date=Apr 4 2006, 04:39 PM:name=Anidazen)--][div class=\'quotetop\']QUOTE(Anidazen @ Apr 4 2006, 04:39 PM) [snapback]361788[/snapback][/div][div class=\'quotemain\'][!--quotec--] Nobody can help me? :( [/quote] Yes, well it's a form, so one common solution to that is to use the CURL library calls.
  16. Although Daiwa offers an interesting facility, I think it's pretty clear that using a switch() isn't a substitute for function overloading. In function overloading you could simply have a parameter with the same name, only a different datatype as a parameter, and that would be enough to differentiate an overloaded function. Since PHP really doesn't care about what type of parameter you pass to a function, it's just not a good platform for function overloading I"m afraid.
  17. It would just take a really long time to go through all the features that Oracle has. It has a long long head start on the competition, and has every feature imaginable in the relational database world.
  18. Certainly. You can load a file into an array using the file function. You could parse each line into further pieces using explode, if for example it was in the format: Starttime, Endtime, Name From there, you simply are left with the exercise of writing a function that determines which program is currently on the air.
  19. Better yet, take a look at the site http://www.opensourcecms.com which not only has news information and links to the major PHP based cms systems, forums and wikis, but also has demos of them installed that you can play with.
  20. Oh yeah, in case you were wondering, you can see this in action at http://www.movie-gurus.com/ in that the News section is the data pulled from the feeds. You have to click on a news item to get to the abstract view for a story, but that small paragraph is what gets pulled in in the description.
  21. A couple other things so you don't get confused by my code. - I don't want to insert duplicate new stories in my news table, so I avoid that using either th guid or the link. When I wrote this the assumption was that I would have multiple news sources so I wasn't sure if they would all support a guid (many don't) which is the equivalent of a unique url. So it should be pretty obvious that the class reads all the items and creates an array of them. I loop through them and inside the loop assign a temp variable item that is just one of the rss entries. $item = $rs['items'][$i]; The important line to note is this one: $sql .= "$nsid, $defstate, '$item[guid]', '$pubdate', '$item[title]', '$item[description]', '$item[link]')"; Here you can see the class item names: $item['guid'] -> the unique url $item['pubDate'] -> The publish date. I have some date manipulation code in there you might find of interest, so i can convert it into a date mysql is happy with. $item['title'] -> The Title $item['link'] -> The link $item['description'] -> The text abstract you are looking for (usually the first n lines)
  22. I looked at Magpie and decided it was a bit heavier than what I wanted. I opted instead to use this class: LastRSS. It probably works in a similar manner to magpie. Here's some sample code that I used, to give you an idea. $rss = new lastRSS(); if ($rs = $rss->Get('http://... put url of xml feed here'')) { $dbh = mysql_connect($DBHOST, $DBUSER, $DBPWD) or die(); mysql_select_db($DBDB); if ($rs['items_count'] > 0) { for ($i=$rs['items_count']-1; $i--; $i >= 0) { $item = $rs['items'][$i]; foreach ($item as $key => $value) $item[$key] = addslashes($value); //YYYY-MM-DD HH:MM:SS (MYSQL FORMAT) $pubdate = date('Y-m-d h:i:s', strtotime($item['pubDate'])); if (!empty($item['guid'])) { $sql = "SELECT COUNT(*) AS countof FROM mg_news WHERE guid = '$item[guid]'"; } else { $sql = "SELECT COUNT(*) AS countof FROM mg_news WHERE url = '$item[link]'"; } echo "$sql<br \>"; $rslt = mysql_query($sql, $dbh) or die(MYSQL_ERROR()); $row = mysql_fetch_assoc($rslt); //Tue, 14 Sep 2004 22:21:39 if ($row['countof'] == 0) { $sql = 'INSERT INTO mg_news (mg_newssource_id, int_state, guid, date, subject, news, url) VALUES ('; $sql .= "$nsid, $defstate, '$item[guid]', '$pubdate', '$item[title]', '$item[description]', '$item[link]')"; $rslt = mysql_query($sql, $dbh); echo "$sql<br \>"; } else { echo 'Guid or Link exists, skipping<br \>'; } } } } else { echo 'Uh oh, didn\'t work'; } As you should note from my example, the entire purpose of my use here was to get the information into a database table. There are a lot of alternative methods to doing that, which includes the caching to file method. I don't worry about that because I control when this script goes out to the the site and pulls information via cron. They have simpler examples in their documentation. The problem with your writing your cache file is probably a permissions issue. Remember that the webserver process is the one that is writing the file to disk, so you need to make sure that the permissions on the cache directory are such that the webserver user has read/write to that directory.
  23. Well yeah at very least this line is wrong: $query = "SELECT * FROM images WHERE user="$_SESSION[.'username'.]" Order By id"; To be honest that isn't even valid PHP and I don't understand how that could even be parsed and not return a php error. The line you want would be this: $query = "SELECT * FROM images WHERE user= '$_SESSION[username]' Order By id";
  24. Your apache httpd.conf is not configured correctly to recognize .php files as requiring php parsing. There's a number of possible reasons for this. Make sure first off that you have an addtype statement for .php files, or reread the installation instructions for php and make sure you have not missed something. Detailed php installation instructions can be found at php.net.
  25. No you don't. Websites all across the internet get along fine without using it. Maybe if you explained what you are trying to do, we could explain to you how you could do it without using an iframe.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.