On MouseOver doTooltip in phpmysql - php

HI Please help to fix this code , i use TITLE
in this code but its not work
<?
$sql = "select * from wallpaper order by wallpaperid desc limit 20";
$result = mysql_query($sql, $db) or die(mysql_error());
if(mysql_num_rows($result)) {
while($myrow = mysql_fetch_array($result)) {
$title = substr($myrow['title'] ,0,31);
$wurl = ereg_replace(" ", "-", $myrow['title']);
$html = '<dt>%s..</dt>';
printf($html, $wurl, $myrow["wallpaperid"], $myrow["wallpapername"], $myrow["title"], $category);
} }
?>
plsease someone help me to fix this
Second code not work onmouseOver TIP

First of all, this is purely a front-end (that is, Javascript/HTML) problem. It has nothing to do with PHP. You haven't actually provided enough information to help pinpoint the issue. It would be much more helpful to see your "doTooltip" and "hideTip" javascript functions.
That said, I notice that you're attempting to use variables $siteurl, $wallpapername, and $wallpaperid variables in your link string. You cannot use PHP variables in a string delimited with ' (single quotes).
Try this:
$html = '<dt>%s..</dt>';
But I suspect that this isn't related to the problem you're actually trying to solve. I'd recommend that you revise your question. Leave out the PHP this time and only show the final output generated by your script. Good luck!

Related

Unreachable Statement in PHP

require_once 'C:/wamp/www/FirstWebsite/CommonFunctions.php';
function SelectRowByIncrementFunc(){
$dbhose = DB_Connect();
$SelectRowByIncrementQuery = "SELECT * FROM trialtable2 ORDER BY ID ASC LIMIT 1";
$result = mysqli_query($dbhose, $SelectRowByIncrementQuery);
$SelectedRow = mysqli_fetch_assoc($result);
return $SelectRowByIncrementQuery;
return $SelectedRow; //HERE is the error <-------------------------------
return $result;
}
$row = $SelectedRow;
echo $row;
if ($row['Id'] === max(mysqli_fetch_assoc($Id))){
$row['Id']=$row['Id'] === min(mysqli_fetch_assoc($Id));#TODO check === operator
}
else if($row['Id']=== min(mysqli_fetch_assoc($Id))){
$row['Id']=max(mysqli_fetch_assoc($Id));#TODO check === operator //This logic is important. DONT use = 1!
Ok, I am trying to write a program for the server end of my website using PHP. Using Netbeans as my IDE of choice I have encountered an error while attempting to write a function which will store a single row in an associative array.
The issue arises when I try to return the variable $SelectedRow. It causes an 'Unreachable Statment' warning. This results in the program falling flat on its face.
I can get this code to work without being contained in a function. However, I don't really feel that that is the way to go about solving my issues while I learn to write programs.
Side Notes:
This is the first question I have posted on SO, so constructive criticism and tips are much appreciated. I am happy to post any specifications that would help an answer or anything else of the sort.
I do not believe this is a so-called 'replica' question because I have failed to find another SO question addressing the same issue in PHP as of yet.
If anybody has any suggestions about my code, in general, I'd be stoked to hear, as I have only just started this whole CS thing.
You can only return one time. Everything after the first return is unreachable.
It's not entirely clear to me what you want to return from that function, but you can only return one value.
The return command cancels the rest of the function, as once you use it, it has served its purpose.
The key to this is to put all of your information in to an array and return it at the end of the function, that way you can access all of the information.
So try changing your code to this:
require_once 'C:/wamp/www/FirstWebsite/CommonFunctions.php';
function SelectRowByIncrementFunc(){
$dbhose = DB_Connect();
$SelectRowByIncrementQuery = "SELECT * FROM trialtable2 ORDER BY ID ASC LIMIT 1";
$result = mysqli_query($dbhose, $SelectRowByIncrementQuery);
$SelectedRow = mysqli_fetch_assoc($result);
$returnArray = array();
$returnArray["SelectRowByIncrementQuery"] = $SelectRowByIncrementQuery;
$returnArray["SelectedRow"] = $SelectedRow;
$returnArray["result"] = $result;
return $returnArray;
}
And then you can access the information like so:
$selectedArray = SelectRowByIncrementFunc();
$row = $selectedArray["SelectedRow"]
And so forth...

PHP Printing a string with multiple single quotes

So I'm having an issue that seems like it should be a pretty simple fix but I can't seem to figure it out.
I'm using prepared statements to query data from my SQL and the return is correct. I have var_dumped the result and confirmed the the information is there.
The table shows this: 2 'all of the way'
The array variable shows this: 2 \'all of the way\'
But when I echo it to the page, I see this: 2
I have tried htmlspecialchars, htmlentities, addslashes, stripslashes and a few combinations of those. Is there a function I'm missing here? Google isn't really helpful because the words to describe the problem are pretty generic.
Thanks in advance!
EDIT
Sorry - didn't add my code because I assumed it was a function I wasn't familiar with. Here it is.
$Res = $db -> query("SELECT * FROM 01_02_item WHERE ParID = $ParID AND active = 1 ORDER BY OrderID") -> fetchAll(PDO::FETCH_ASSOC);
if(empty($Res[0])) $return = "<span class = 'nodata'>No data</span>";
foreach($Res as $r){
$id = $r['id'];
$name = htmlspecialchars($r['Name']);
$title = stripslashes(htmlspecialchars($r['Description']));
$return .= "<li href = '$id' title = '$title' name = '$name'>$name</li>";
}
return $return;
By default htmlspecialchars() doesn't escape single quotes.
You should use htmlspecialchars('foobar', ENT_QUOTES).

Tab indents showing in database, but not when echoed to page using php

I have enabled tab indents on a textarea, and when I look in phpmyadmin at my database, it shows the indents intact. However, when I try to echo it to the page using php, it does not preserve the tabs. It does preserve the line breaks. I am using nl2br().
I have done countless searches on it, but I keep getting questions about to to preserve tab indents when posting to the database. I am looking for the next step. Could someone please show me a technique or mark this as duplicate so I can find my answer?
<?php
$sql = "SELECT *
FROM talk
WHERE id = ( SELECT MAX(id) FROM talk ) ;";
if ($result = mysqli_query($con, $sql))
{
while($row = mysqli_fetch_assoc($result))
{
echo '<left><p>'.nl2br($row['post']).'</p></left> ';
}
}
?>
Use str_replace to replace tab's with 3-5 nbsp's.
eg.
echo str_replace("\t", " ", $yourstring);

Displaying users with a php, sql count?

I have a database with users input and was wanting to output a user table (id, username) as a count on a page. The following piece of code is what I've been trying to work with but I've been having no luck and it keeps getting more and more complex - the SQL works perfectly so I'm not sure what's wrong.
mysqli_select_db($db);
$result = $_POST ['$result'] ;
$result = mysqli_query("SELECT COUNT( * )
FROM users");
$row = mysqli_real_escape_string($result,$db);
$total = $row[0];
echo "Total rows: " . $total;
I'm still learning how to properly link SQL in with PHP. The warnings tell me to add an extra parameter however when I do so it still complains.
I originally wanted a simple COUNT but will change the count to a table array if need be. I understand this maybe a little basic and I may have been going about it the wrong way, but I've hit a wall with it and any help on fixing the COUNT would be greatly appreciated
Replace the call to mysqli_real_escape_string to mysqli_fetch_array and your code will works.
mysqli_real_escape_string is only useful for string escaping when you INSERT or UPDATE data to MySQL.
$row = mysqli_fetch_array ($result);
Please try this code:
$sql="SELECT * FROM users";
$result=mysqli_query($con,$sql);
// Numeric array
$row=mysqli_fetch_array($result,MYSQLI_NUM);
$number = count($rows);
Hope this works.

Reading from mysql table issue

I'm dealing with strange problem.
$result = mysql_query("SELECT link FROM item WHERE item_id='$id2'") or die(mysql_error());
$row = mysql_fetch_assoc($result);
$picture = ''.$row['link'].'';
echo"$picture";
Gives me result http://127.0.0.1/1321426277. without ending, while in column link link is: http://127.0.0.1/1321426277.jpg. Why it cuts ending?
For testing purposes please run
$result = mysql_query("SELECT link, Length(link) as l FROM item WHERE item_id='$id2'") or die(mysql_error());
$row = mysql_fetch_assoc($result);
if ( !$row ) {
echo 'no such record';
}
else {
$l = strlen($row['link']);
var_dump($l, $row['l'], $row['link']);
$picture = $row['link'];
echo "'$picture'";
}
and post the result.
I don't see anything in your code that would cause the link to be truncated. Have you checked to make sure you have the correct data in your table?
It looks like a bug in the data. Print out (and select) the ID at both places (the query in your question and the other place where you use it in img src tag). I bet they will differ. Or, you should check SELECT count(1) FROM item WHERE item_id='xxx'*, where xxx is the ID of the magic record.
Ah now I see = the problem is because you code contains an 'r' after the 'o' rather then before - it is so clear now because you provided such a complete example of the behavior that I replicate on my machine.
WTF

Categories