Forum Moderators: coopster

Message Too Old, No Replies

Make a pop up window with my MySQL data

Need to make my database results pop up in a new mindow

         

togethercomms

8:18 am on Jun 30, 2009 (gmt 0)

10+ Year Member



My Client has asked if i can make the results from the database pop up in a new window,
i knew it was possible but with javascript, don't really like using javascript as i never got trained on it.

I was wondering if their was a way to make this link pop up in a new window if poss.

<a href=\"job-info.php?id=".$id."\">I'm Interested</a>

Many Thanks

penders

11:37 am on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could add a target attribute to your anchor...
<a href="job-info.php?id='.$id.'" target="_blank">I'm Interested</a>

You will need to use a Transitional DOCTYPE.

togethercomms

11:44 am on Jun 30, 2009 (gmt 0)

10+ Year Member



i tried that, i need it in a new window

barns101

12:10 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



As penders said, target="_blank" is the code to open the link in a new window. If you want to customise that window (e.g. no toolbars etc...) you will need to use JavaScript or a Lightbox-type effect.

penders

12:32 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i tried that, i need it in a new window

When you use

target="_blank"
what happens? If, for instance, it opens a new tab instead then that is a configuration setting within the browser.

togethercomms

1:55 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



oh didn't think it like that, i'll use the "_blank"
Many Thanks all

togethercomms

2:35 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



as we are talking about buttons, could someone have a look at this and make sure it is ok as it's not working.

I click the button and nothing happens, i might not have the query correct.

Many Thanks

$sql = "SELECT * FROM job_board";
$res = mysqli_query($mysqli, $sql);

if($res) {
while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
$id = $newArray['id'];
$title = $newArray['title'];
$short = $newArray['short'];
$salary = $newArray['salary'];
$end_date = $newArray['end_date'];
echo "<div id='border'>";
echo "<div class='bg'><div class='subject'>".$title. "&nbsp; &nbsp; &nbsp; &nbsp; &pound;" .$salary."</div></div>";
echo "<div class='body'>".$short."</div>";
echo "<input type='submit' name='delete' id='delete' value='Delete'>";
echo "</div><br>";
}
} else {
printf("Could not retrieve records: %s\n", mysqli_error($mysqli));
}

if(isset($_POST['delete'])) {
$query = "DELETE FROM job_board WHERE id=?$id";
mysql_query($mysqli, $query) or die('Error : ' . mysql_error());
echo "job deleted";

}

} else {
echo "Could not delete job";
}

jatar_k

2:46 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



when you say not working do you get an error? or how is it not working.

or if it is this call

mysql_query($mysqli, $query) or die('Error : ' . mysql_error());

you need to either use mysqli_query or remove the first var from the call

togethercomms

3:47 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



i dont get any errors, everything is connecting to the database and showing the results, but it is not recognising the delete command it does nothing, it's like a dead button

LifeinAsia

3:56 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



ECHO $query to make sure the query is what you expect it to be.

togethercomms

4:08 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



im getting nothing from the echo, this is really wierd, it's like the php and mysql arn't connecting, but i know they are

LifeinAsia

4:28 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I think you have an extra close bracket in there...

togethercomms

4:32 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



still nothing, but good spot

penders

4:48 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Presumably you have
<form method="post"...
in your code?

$query = "DELETE FROM job_board WHERE id=?$id"; 
echo $query;

im getting nothing from the echo

By the sounds of it $_POST['delete'] is not set. Is that "?" necessary?

jatar_k

5:07 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



penders has it

as I mentioned unless your code is different than what is here

this line doesn't work

mysql_query($mysqli, $query)

in your other queries you show that $mysqli is your connection and for that function you need to feed it query first, or you need to change to mysqli_query

just making sure that was done or nothing will work, and if it does work without changing it then you have another unknown error

at this point I would repost the code so that we could see what changes have been made, there have been a lot of catches

rocknbil

9:16 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



target="_blank" is the code to open the link in a new window.

Maybe it's just my configuration, but this opens a new tab, not a new window. I've never set it that way, and it's the same in both IE and FF, so I'm thinking it's a default configuration?

Paste this anywhere between <head> and </head>:
<script type="text/javascript">
function newWin(url,w,h) {
var day = new Date();
var id = day.getTime();
var params='width='+w+'.height='+h+',resizable,scrollbars';
var win = open(url,id,params);
return false;
}
</script>

Then for every link you need,

<a href="file.html" onclick="return newWin('file.html',600,600);">new window</a>

Control the width and height with the last two numbers.

Per your PHP problem, I don't see form tags which may be the problem, but also you have

echo "<input type='submit' name='delete' id='delete' value='Delete'>";

if(isset($_POST['delete'])) {
$query = "DELETE FROM job_board WHERE id=?$id";
.....

Where does $id get set? Id you echo'ed $_POST['delete'], you would get

Delete

Because that's the submitted value of delete. You would probably need to do something like this:

echo "<input type=\"hidden\" name=\"delete_id\" value=\"$id\">";
echo "<input type='submit' name='delete' id='delete' value='Delete'>";

if(isset($_POST['delete_id'])) {
$query = "DELETE FROM job_board WHERE id=".$_POST['delete_id'];
.....

or

if(isset($_POST['delete']) and ($id==$_POST['delete_id'])) {
$query = "DELETE FROM job_board WHERE id=$id";
.....
Of course, the variable delete_id should be cleansed before performing the delete, but that's the Cliff notes . . .