Jump to content

ghop2003

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ghop2003's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm trying to create a simple CMS for people to contribute to my site. I know I need to use fopen() or mkdir() or possibly both. What I'm confused about is what they exactly do. I know to use something like $fh = fopen($filename, 'w') to open a file to write to. And, I know it creates the file if it doesn't exist. I think this is the correct way to use mkdir: mkdir("path/to/dir", 0777). What I want to know is if fopen can actually create the directory or work in a directory different from where the file is located? For example, I have create.php (which has fopen) in /path/to/dir1 and I want to create the file in /path/to/dir2. If that path doesn't exist, will fopen() create it or do I have to use mkdir() to create it? Can I write to that directory after it is created using fopen()? I don't know if I made any sense here, but if I did, could someone help me?
  2. I figured it out. I thought I'd post in case anyone else has a similar problem. This section of the code: [code]$query  = 'SELECT title, year, platform, genre, owner, review_url FROM games LIMIT $offset, $rowsPerPage'; if ($cat==NULL or $val==NULL)   $query .= ' ORDER BY '; else   $query .= ' WHERE '.$cat.' LIKE \''.$val.'\' ORDER BY '; $query .= $sort; $result = mysql_query($query) or die('Query failed: ' . mysql_error());[/code] needs to be changed to this: [code]$query  = "SELECT title, year, platform, genre, owner, review_url FROM games "; if ($cat==NULL or $val==NULL)   $query .= " ORDER BY "; else   $query .= " WHERE '.$cat.' LIKE \''.$val.'\' ORDER BY "; $query .= $sort; $pagingQuery = " LIMIT $offset, $rowsPerPage "; $result = mysql_query($query . $pagingQuery) or die('Query failed: ' . mysql_error());[/code] Like I said before, I don't really know PHP all that well, but I'm guessing the problem had something to do with the ordering of the query (as well as the syntax). I saw this in an example for different php code and gave it a try. It worked.
  3. [!--quoteo(post=385389:date=Jun 18 2006, 03:28 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 18 2006, 03:28 PM) [snapback]385389[/snapback][/div][div class=\'quotemain\'][!--quotec--] first off, when concactinating strings, make sure it gets properly spaced. Look at your error: 20ORDER BY title. You can see there that there is no space between 20 and ORDER. add a space in this line (notice the space between the ' and the O) $query .= ' ORDER BY '; and you are going to get the same error in your else condition as well. you need to do ' WHERE' not 'WHERE' [/quote] Thanks for the quick reply. That kind of worked. Now I get this error message: Query failed: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY title' at line 1 I have no idea what to do with that part. I'm thinking it deals with the same section of my code but if it would help, I can include my whole code.
  4. I'm having trouble getting my php code working. I don't really know php all that well. I mainly cut and paste what others have done. This is the error message I get: Query failed: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '20ORDER BY title' at line 1 Here is the part of the code that I think is relevant (if you need more code, let me know): [code]// how many rows to show per page $rowsPerPage = 20; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) {     $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; // Performing SQL query $cat = $_GET['cat']; $val = $_GET['val']; $sort = $_GET['sort']; if ($sort==NULL)   $sort = 'title'; $query  = "SELECT title, year, platform, genre, owner, review_url FROM games LIMIT $offset, $rowsPerPage"; if ($cat==NULL or $val==NULL)   $query .= 'ORDER BY '; else   $query .= 'WHERE '.$cat.' LIKE \''.$val.'\' ORDER BY '; $query .= $sort; $result = mysql_query($query) or die('Query failed: ' . mysql_error());[/code] I'm pretty sure it has to do with the first query and second query calls, but I don't know how to fix it. Any help would be appreciated.
  5. I pasted my code below. It isn't my own code, I got it from somewhere that I can't remember and modified it. Right now, to see some entries i use a link like index.php?cat=*&val=*. I want to add another modifier. I'm trying to order the database by something other than 'title' initially. For example, to order by genre, I want something to use a link like index.php?cat=*&val=*&order=genre. I added this code right before the '//Performing SQL query' comment. [!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--]$default_sort = 'title'; $allowed_order = array ('title', 'director','year','genre','owner'); /* if order is not set, or it is not in the allowed * list, then set it to a default value. Otherwise, * set it to what was passed in. */ if (!isset ($_GET['order']) || !in_array ($_GET['order'], $allowed_order)) { $order = $default_sort; } else { $order = $_GET['order']; }[!--sizec--][/span][!--/sizec--] Then, I place $order in the ORDER BY section of the query, but it doesn't seem to work. I've tried ORDER BY $order'; and ORDER BY '$order'\'; Any help would be appreciated. [!--sizeo:1--][span style=\"font-size:8pt;line-height:100%\"][!--/sizeo--]<?php // Connecting, selecting database $link = mysql_connect('localhost', '******', '******') or die('Could not connect: ' . mysql_error()); mysql_select_db('dvdswapn_movies') or die('Could not select database'); // Performing SQL query if ($_GET['cat']=='*' or $_GET['cat']==NULL) $query = 'SELECT title, director, year, genre, cover, owner, review_url, cover_url FROM movies ORDER BY title'; else $query = 'SELECT title, director, year, genre, cover, owner, review_url, cover_url FROM movies WHERE '.$_GET['cat'].' LIKE \''.$_GET['val'].'\' ORDER BY title'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML echo "<table width=100% border=0 cellpadding=3 cellspacing=0>\n"; echo "\t<tr bgcolor=#222>\n"; echo "\t\t<td><font size=\"-6\"><u>Title</u></font></td>\n"; echo "\t\t<td><font size=\"-6\"><u>Director</u></font></td>\n"; echo "\t\t<td><font size=\"-6\"><u>Year</u></font></td>\n"; echo "\t\t<td><font size=\"-6\"><u>Genre</u></font></td>\n"; echo "\t\t<td><font size=\"-6\"><u>Cover Image</u></font></td>\n"; echo "\t\t<td><font size=\"-6\"><u>Owner</u></font></td>\n"; echo "\t</tr>\n"; $count = 0; while ($line = mysql_fetch_array($result, MYSQL_BOTH)) { $count++; if($count%2) echo "\t<tr bgcolor=#1E1E1E>\n"; else echo "\t<tr bgcolor=#222>\n"; echo "\t\t<td><font size=\"-6\"><a href=\"$line[review_url]\">$line[title]</a></font></td>\n"; echo "\t\t<td><font size=\"-6\">$line[director]</font></td>\n"; echo "\t\t<td><font size=\"-6\">$line[year]</font></td>\n"; echo "\t\t<td><font size=\"-6\">$line[genre]</font></td>\n"; echo "\t\t<td><font size=\"-6\"><a href=\"$line[cover_url]\">$line[cover]</a></font></td>\n"; echo "\t\t<td><font size=\"-6\">$line[owner]</font></td>\n"; echo "\t</tr>\n"; } echo "</table>\n"; echo "<hr align=\"left\" width=60% size=1 color=\"#B0B0B0\">\n"; echo "<font color=\"#B0B0B0\">$count results</font>\n"; // Free resultset mysql_free_result($result); // Closing connection mysql_close($link); ?> [!--sizec--][/span][!--/sizec--]
×
×
  • 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.