AdRock
-
Posts
913 -
Joined
-
Last visited
Posts posted by AdRock
-
-
WELCOME TO THE MEMBERS AREA <?php echo $_SESSION['username']; ?>
-
I was thinking about switch/case but not sure what to put between the brackets of the switch Would i put switch($parts) and have nested switch i.e. switch($parts) { switch($i-1) { } switch($i-2) { } }
-
it's a bit harder looking at this script cos using edit/delete is different.
Basically for the edit you need to create a select query using an id in the where clause and echo the results into a form (probably the same form as creating a topic) then when the user submits the form you need to do an update query using the same id in the where clause.
As for the delete, if you have a link/button, you would execute a query to delete from database using the same id in the where clause.
-
you need to explain a bit better than that.
How is the user entering the urls? in a form? Where are the urls being saved? database? text file?
-
I have some code which i think is really inefficient especially as there will be more more conditions to be met.
I was thinking about using s switch but don't know if this is possible or if it's best leaving as it is.
Any ideas?
if($parts[($i-1)]=="forum") { //do some code } else if($parts[($i-2)]=="forum") { //do code } else if (($parts[($i-1)]=="list-messages") && (isset($parts[($i+1)]))) { //do code } else { // do some code }
-
-
Don't quote me as I do forms a different way but what about this line?
if (!empty($_POST)) {
I'm pretty sure that won't pass unless all fields are entered
-
I have a breadcrumb scrpt that works well except I want it to be like the breadcrumb script here on phpfreaks.
I need to get parts of the url that the script gets to create the trail and query the database to replace those parts of the url.
Say i have a url like mydomain.com/forum/1/2, where 1 is the board and 2 topic, how would i change the code so if the part[1] was forum it replaces parts 2 and 3 with what it's in the database?
Here is my breadcrumb script
function breadcrumb( $home = 'Home', // Name of root link $division = ' / ', // Divider between links $hidextra = true, // Toggle hide/show get data and fragment in text $index = false, // Toggle show/hide link to directory if it does not contain a file $indexname = 'index.php' // The definition of the file the directory must contain ) { $breadcrumb=""; // Requested addons... $extension = '.php'; // Extension to cut off the end of the TEXT links $ifIndex = 'index.php'; // Filename of index/default/home files to not display // End requested addons $whole = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $parts = explode('/', $whole); $parts[0] = 'http://'.$parts[0]; $array = array('-', '%20'); $breadcrumb .= "<a href=\"{$parts[0]}\">{$home}</a>{$division}"; $k = 1; for ($i=1;$i < sizeof($parts);$i++) { $uri = '/'; while ($k <= $i) { $uri .= $parts[$k]; if ($k != (sizeof($parts)-1)) $uri .= '/'; $k++; } if (($index && is_dir($_SERVER['DOCUMENT_ROOT'].$uri) && is_file($_SERVER['DOCUMENT_ROOT'].$uri.$indexname) || !$index || !is_dir($_SERVER['DOCUMENT_ROOT'].$uri)) && $parts[$i] != $ifIndex) { $breadcrumb .= "<a href=\"$uri\">"; if ($hidextra) { $breadcrumb .= rtrim(preg_replace("/\?.*$/", '', ucwords(str_replace($array," ",$parts[$i]))), $extension); } else { $breadcrumb .= rtrim(ucwords($parts[$i]), $extension); } $breadcrumb .= '</a>'; } else { $breadcrumb .= ucwords(str_replace($array," ",$parts[$i])); } if (isset($parts[($i+1)])) { $breadcrumb .= $division; } $k = 1; } return $breadcrumb; }
-
I don't know if this is a SQL problem and a PHP problem
I made my own search engine for my site and I hve got links that point to pages. The problem is that the link i create has to right page i want to show and i can show the page by editing my code but i won't have any pagination links
Say i have a link called news.php?id=10 i can follow the link and i could show the page but i want to be able to show the extra links for other news. This id may be the 7th record in the database so i would have 6 links before it
Is there a way i can find out the position that record is in the database or is there another way i can do it so that the pagination link of this page is in the correct place
At the moment with the code i've shown it shows the first record in the database and i have a theory if i can get the position of the record in the database i can say what pagenum it should be
<?php require_once('php/database/MySQL.php'); require_once('php/database/connection.php'); require_once('php/init.php'); // Include the header html require_once("header.inc.php"); ?> <h1>Latest News</h1> <div id="news"> <?php $dir = "about"; $path = "latest-news"; $webpage = basename($path); $db = & new MySQL($host,$dbUser,$dbPass,$dbName); $count="Select COUNT(*) FROM news"; $sql="SELECT * FROM `news`"; // Perform a query getting back a MySQLResult object $res = $db->query($count); $result = $db->query($sql); //get the number of rows in datatbase $getresult = $result->size(); $numrows = $res->fetchrow(); if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1); $entries_per_page = 1; $total_pages = ceil($numrows[0]/$entries_per_page); $offset = (($page * $entries_per_page) - $entries_per_page); $sql="SELECT * FROM `news` LIMIT $offset,$entries_per_page"; // Perform a query getting back a MySQLResult object $result = $db->query($sql); $err = $result->size(); if($err == 0) { echo ("No matches met your criteria."); } else { // Iterate through the results while ($row = $result->fetch()) { $content = htmlentities($row['content']); echo '<div id="images"> <img src="images/honeylandsbuilding.jpg" alt="Honeylands building" title="Honeylands building" class="divimg" /> <img src="images/front.jpg" alt="Honeylands front entrance" title="Honeylands front entrance" class="divimg" /> </div><p>'.nl2br($row['content']).'</p>'; } //or after the results if($getresult > 1) pagination_one($total_pages,$page);; } echo "</div>"; require_once("footer.inc.php"); ?>
-
I saw that but that wasn't the problem
I had to do the str_replace first then call the function but it now works
-
function ShortenText($text, $chars) { $text = $text." "; $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text."..."; return $text; } $placeholders = array($keywords, $uckeywords); $vals = array("<span class='searchbold'>$keywords</span>", "<span class='searchbold'>$uckeywords</span>"); $link = str_replace($placeholders, $vals, $title); $add = str_replace($placeholders, $vals, $content); $add = ShortenText(str_replace('&', '&',$add,500);
How do i fix the error
?Only variables can be passed by referenceI want to replae the keywords with bold text and also change the ampersands to &
-
Don't understand what the question is
-
Just looking for some advice on how to do this. I can probably code it if someone tells me the best way to do this
I want to connect to the database and from one field in the database (e.g. colours) I want to get all possible values and count how many times each value occurs.
I then want to create an associative array with each vale and how many times that value occured e.g.
Red => 10
Yellow => 5
Green => 3
Blue => 7
I know I can create an array of the colours (or whatever i want) and I know I can comibe the arrays but how would I get each value to increment?
Would I use a switch statement inside the while loop from query that checks the value and increments the variable assingned to the value each time it occurs
while ($row = mysql_fetch_array($result) { switch($row['field']) { case 'red': $red++; break; case 'yellow': $yellow++; break; case 'green': $green++; break; case 'blue': $blue++; break; default: } }
If i do it that way how do i get all those variables into an array so i can comibne the 2 arrays?
Any help or advice appreciated
-
-
First question would be to give the TDs a class name and use css to hide the borders
Second question I don't understand what you want to do
-
I installed Apache, PHP and MySQL for a friend and it all seems to work accept windows 7 won't start the apache service automatically. There is an error 1067.
Using net start apache doesn't work either
The only way to start apache is but calling it from the command line
cd c:\Apache\apacheAny ideas how to fix this?
-
Looks to me like you are being redirected before the mail is sent
header("Location: ".$session->referrer);
-
-
$sql="SELECT userid FROM members WHERE userid='$user_id' LIMIT 1"; $result = mysql_query($sql); $numrows = mysql_num_rows($result); if($numrows == 0 ) { mysql_query("INSERT INTO members (userid, paid) VALUES ('$user_id', '0')"); } else { //already inserted }
-
Are you not using sessions?
You could use secure sessions
-
Doing this
$result = mysql_query ("UPDATE Agency_Contacts SET CATEGORY = '$CATEGORY'");
will update ervery row becuase you didn't ell it which row to update. That will update all rows. You need to specify a WHERE clause at the end of the query
Also I don't see any $_POST variables so i don't know how you're inserting anything in the database
Have a look here http://www.plus2net.com/php_tutorial/site_map.php for some nice tutorials on PHP or even http://www.tizag.com/
-
You need
if(!$error)
so if it doesn't do the query echo the error
-
I presume you would have the class details stored in the database such as "wrong" with all the style information?
-
Totally untested but give this a try
echo '<div class="contenttopcenter2"><img src="'.$imageurl.'" '.imageResize($rcimage[0],$rcimage[1], 125).' />"';
extract part of a string
in PHP Coding Help
Posted
I have string like this (without the spaces)
[ QUOTE=Adrock]This is a test message[/quote ]
How do i get just what is between the double quotes taking into account in the message there could be double quotes?
I've tried this but it doesn't echo anything unless i put the square brackets in but i want the username