wildteen88
Staff Alumni-
Posts
10,480 -
Joined
-
Last visited
Never
Everything posted by wildteen88
-
This topic has been moved to PHP Coding Help. http://www.phpfreaks.com/forums/index.php?topic=308893.0
-
You shouldn't need to alter your tables when a new thread or comment is added. You should set up two tables which are called threads, and comments. The basic table structure would be Threads ---------- thread_id auto_increment thread_title thread_poster thread_body Comments ------------- comment_id auto_increment thread_id comment_poster comment_body When you add a thread you insert it into the threads table. All comments to that thread will go into the comments table. You link the comment to the thread by inserting the threads id into the thread_id column within the comments table. The query you'd use to get all comments associated with the thread would be SELECT comment_title, comment_body, comment_author FROM comments WHERE thread_id='$thread_id'
-
now i want to rewrite a friendly url
wildteen88 replied to deansaddigh's topic in Apache HTTP Server
The ^ just tells mod_rewrite to match from the start of the url. It wont make any difference with or without it. The reason you got the error before was because of the space between NC, and L. NC stands for No Case (which mean make the match case-insensitive). L stands for Last rule. Have a read of the Apache Documentation on mod_rewrite. It will help you to understand how mod_rewrite functions. For learning regex (regula expressions) you'll find regular-expressions.info a good resource. -
now i want to rewrite a friendly url
wildteen88 replied to deansaddigh's topic in Apache HTTP Server
Yes you can have as many RewriteRules as you like. When having many rewriteRules add the [L] flag after each one. RewriteEngine on RewriteRule ^(.*)\.htm$ $1.php [NC, L] RewriteRule school/([a-z_-]+)/? school_details.php?id=$1 [L] Yes you will need to change your links to <a href="school_details/'.$name.'"> Change the rewriteRule to RewriteRule school_details/([a-z_-]+)/? school_details.php?id=$1 [L] -
For the displaying N/A if email is NULL. Change this <td align="left">' . $row['manager_email'] . '</td> To <td align="left">' . (!empty($row['manager_email']) ? $row['manager_email'] : 'N/A') . '</td> For adding alternative row colours add $i = 0; $color1 = '#CCCCFF'; $color2 = '#CCFFFF'; NOTE: Set your two alternative colours above Before while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { Now change echo '<tr bgcolor="' . $bg . '"> To $bg = ($i++ % 2) ? $color1 : $color2; echo '<tr bgcolor="' . $bg . '">
-
When outputting results vertically, eg 1 6 11 2 7 12 3 8 13 4 9 14 5 10 15 You'll have to loop through the results a bit differently. $query = "SELECT adsubcat.name AS subname, adsubcat.linkname AS sublink, adcat.clinkname AS clink FROM adsubcat JOIN adcat ON adcat.id=adsubcat.catid WHERE adsubcat.catid='$catid' ORDER BY adsubcat.name ASC"; $result = mysql_query($query) or die(mysql_error()); // add all the rows into the $results multi-dimensional array $results = array(); while ($row = mysql_fetch_assoc($result)) $results[] = $row; /* Here is how we output the results vertically */ // set the number of columns $cols = 3; // work out how many rows will be needed $rows = ceil(count($results) / $cols); echo '<table style="text-align:left;margin-left:0px;width:943px;">'."\n"; // output the rows for($j = 0; $j < $rows; $j++) { echo " <tr>\n"; // output the columns for($i = 0; $i < $cols; $i++) { $x = ($i*$rows)+$j; if(isset($results[$x])) { $row = $results[$x]; echo ' <td><a href="'.$root.'/'.$row['clink'].'/'.$row['sublink'].'">'.$row['subname']. "</a></td>\n"; } else { echo " <td></td>\n"; } } echo " </tr>\n"; } echo '</table>';
-
Your query will be like this SELECT m.name as manager_name, m.email as manager_email, c.name as company_name FROM Managers m LEFT JOIN Company c ON c.companyid = m.companyid So your complete code would be $query= "SELECT m.name as manager_name, m.email as manager_email, c.name as company_name FROM Managers m LEFT JOIN Company c ON c.companyid = m.companyid"; $result = mysql_query($query); echo mysql_error(); echo '<table align="center" cellspacing="1" cellpadding="2"> <tr> <td align="left"><b>Name</b></td> <td align="left"><b>Email</b></td> <td align="left"><b>Company</b></td> </tr> '; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo '<tr bgcolor="' . $bg . '"> <td align="left">' . $row['manager_name'] . '</td> <td align="left">' . $row['manager_email'] . '</td> <td align="left">' . $row['company_name'] . '</td> </tr> '; }
-
now i want to rewrite a friendly url
wildteen88 replied to deansaddigh's topic in Apache HTTP Server
If you want your url to be site.com/schools/school_name/ Then the rewriterule will be rewriteRule school/([a-z_-]+)/? school_details.php?id=$1 This will then map site.com/schools/school_name to site.com/school_details.php?id=school_name However you may need to alter school_details.php so it grabs the school from your databased based on the schools name rather than the schools id. -
I think the issue is you have two while loops. You only need the one. Remove the inner while loop
-
Basic regex pattern ~(cos|sin)\([a-z0-9\.]+\)[+-](cos|sin)\([a-z0-9\.]+\)~ Test code $strings = array( 'sin(x)+cos(x)', 'cos(x)-sin(x)', 'sin(x)-cos(x)', 'sin(x)*cos(x)', 'sin(x)/cos(x)', 'sin(x)+sin(x)', 'cos(x)+cos(x)', ); foreach($strings as $string) { preg_match('~(cos|sin)\([a-z0-9\.]+\)[+-](cos|sin)\([a-z0-9\.]+\)~', $string , $matches); echo $string . ' - ' . ( isset($matches[0]) && ($matches[1] != $matches[2]) ? 'PASS' : 'FAIL' ) . '<br />'; }
-
It depends on how you installed PHP. Did you install PHP from the ubuntu repositories (eg sudo apt-get install php5) if you did then you can download and compile the oci8 extension using pear. Have a read of these guides https://help.ubuntu.com/community/PHPOracle http://ubuntuforums.org/showthread.php?t=92528
-
All you're telling mod_rewrite to do here RewriteRule ^(.*)\.htm$ $1.php [nc] Is to map any url ending in .htm to the corresponding .php file. You havn't told it to prevent the user from accessing the .php file.
-
Streamlining Dreamweaver generated PHP code
wildteen88 replied to MargateSteve's topic in PHP Coding Help
The code generated by Dreamweaver is a complete joke. It is impossible to learn from. Cleaning that code up will be a complete nightmare.You'll be better of starting from scratch. There is no need to have 5 or 6 different queries for getting the manages/goalkeepers/defenders/midfielders/fowards separately. Depending on how you are structuring your tables you should only need to have just one query and one while loop. -
What is the table structure for your Mangers and Company tables? In order to have a join there needs to be a column which associates a manager with the company.
-
No, You don't rename the files. You need to alter the links within your php files.
-
Using php and phpmyadmin on Windows 7
wildteen88 replied to karimali831's topic in PHP Installation and Configuration
Yes you can install Apache, PHP and MySQL locally on your pc. You can ever install them seperately yourself. Or can install a pre configured package such as wampserver. Wampserver comes with Apache, PHP, MySQL and phpMyAdmin -
Multiple lines displayed from mysql string.
wildteen88 replied to elmas156's topic in PHP Coding Help
When you output the text from the database use nl2br -
That will never work as it is invalid code. You'll want to use AbraCadaver example posted earlier: Here's a quick example: <a href="?file=file1">file 1</a> <a href="?file=file2">file 2</a> <a href="?file=file3">file 3</a> <?php if(isset($_GET['file') && file_exists("/path/to/file/".$_GET['file'].".php")) { include("/path/to/file/".$_GET['file'].".php"); } else { // do something else } ?>
-
Display resuls like this with different color?
wildteen88 replied to $php_mysql$'s topic in CSS Help
Basically each table cell/row is given a different background colour with css. A simple example <style type="text/css"> .odd { background-color: #e7eaef; } .even { background-color: #cacdd3; } </style> <table border="0" cellpadding="5" cellspacing="1"> <tr> <td class="odd">xxx</td> <td class="even">xxx</td> <td class="odd">xxxx</td> <td class="even">xxx</td> </tr> <tr> <td class="odd">xxx</td> <td class="even">xxxx</td> <td class="odd">xxx</td> <td class="even">xxx</td> </tr> <tr> <td class="odd">xxxx</td> <td class="even">xxxx</td> <td class="odd">xxxx</td> <td class="even">xxxx</td> </tr> </table> -
If you go to site.com/filename.htm it should call site.com/filename.php Do not assume mod_rewrite will change your links for you. You'll need to change your links from <a href="path/to/filename.php">some link</a> to <a href="path/to/filename.htm">some link</a> yourself. mod_rewrite will only map the url site.com/filename.htm to site.com/filename.php
-
I would be helpful if you told us what are theses "links" are and what you want the included file to be changed to?
-
what you should do then is call nl2br() after your have called bbcode(). Now remove these lines $r = str_replace("\r\n","<br>",$r); $r = str_replace("\r\n","</br>",$r); From your function, they are not needed. nl2br convert newlines to <br /> for you so that above lines are not needed.
-
Do you use a function called nl2br, before you call your bbcode() function?
-
Use the function mysql_num_rows. This function returns how many results was returned from your query. So your code will be $article_rs = mysql_query($article_sql, $mysql_conn); // check that mysql_query ran fine // mysql_query will return false if there is an error if ($article_rs) { // check if any results where returned if(mysql_num_rows($article_rs)) { // process the query results here } // no results, set the error else { $_SESSION['no_articles'] = "<p>Sorry but there are no articles that match your search.</p>"; } } // Problem with mysql_query! Lets see why else { trigger_error('MySQL Error: ' . mysql_error() . '<br />Query: ' . $article_sql, E_USER_ERROR); }
-
Your bbcode() function appears to be fine. Where/how are you calling the bbcode() function to?