homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
calling element from Loop to a new page - help please
php help
neo2sxn




msg:4439896
 5:56 am on Apr 12, 2012 (gmt 0)

Hi,

i am calling images and pdf file downloading links by loop on the page and trying to calling the selected item on new page when a user click the link ..I want that the clicked content should come to new page (final download page),Help me to do it ,This is my coding -

<?php
$i=0;
$sql="select * from software";
$result=mysql_query($sql) or die(Error);
while($row=mysql_fetch_array($result))
{
if($i%3==0)
{
echo "</tr><tr>";
}
?>

<img src="folder1/subfolder/<?php echo $row['sub_category'];?>/Software/preview/<?php echo $row['cat'];?>/<?php echo $row['previewfile'];?>"height="170" width="150"/>

<a href="folder/subfolder/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>"><?php echo $row['title'];?></a>


'sub_catagry' and 'cat' are also sub folders names which i am calling from database.

Thank you

 

cffrost2




msg:4439982
 12:21 pm on Apr 12, 2012 (gmt 0)

Not sure I follow but are you just wanting a new page to open when they click the link? Are your links rendering correctly? If you just want a new page to open for the clicked link, try


<a href="path" target="_new">link text</a>

neo2sxn




msg:4440006
 1:43 pm on Apr 12, 2012 (gmt 0)

Helo cffost2,


i am making pdf download site, So i am calling all the files with preview on the page by loop, But i am not able to post the clicked item to new page (final download page).

See this link to let you understand my problem easily <snip>

[edited by: eelixduppy at 2:32 pm (utc) on Apr 12, 2012]
[edit reason] no personal URLs, please [/edit]

eelixduppy




msg:4440038
 2:38 pm on Apr 12, 2012 (gmt 0)

Does the link you are making actually resolve to the content you want to offer to download? For example, does your HTML look something like this once it is interpreted by PHP:


<a href="folder/subfolder/subcategory/Software/category/file.pdf">title goes here</a>


And then you actually have file.pdf in that path on your server?

Or, are you storing your files someplace else, and you want a download page to fetch this content and offer it to download to the user?

cffrost2




msg:4440062
 3:47 pm on Apr 12, 2012 (gmt 0)

I'm gathering this code:

<img src="folder1/subfolder/<?php echo $row['sub_category'];?>/Software/preview/<?php echo $row['cat'];?>/<?php echo $row['previewfile'];?>"height="170" width="150"/>


is part of the "final download page" to show the image and it's not showing, correct? I assume that use tryed to access the file directly to make sure the url works by entering the url directly in your brower bar. The .jpg/.gif image extension is also in the stored file name?
BTW: put a space between the href quotes and the height attribute.

neo2sxn




msg:4440099
 5:13 pm on Apr 12, 2012 (gmt 0)

eelixduppy,

Yes my html looks like -
<a href="folder/subfolder/subcategory/Software/category/file.pdf">title goes here</a>

After interpreted by php .and my file is stored in the location described by <a ref=""> link.

And yes i want final download page to fetch this content and offer it to download to the user?

neo2sxn




msg:4440102
 5:18 pm on Apr 12, 2012 (gmt 0)

cffrost2,

This is the coding of download page where i am calling all the product -

<img src="folder1/subfolder/<?php echo $row['sub_category'];?>/Software/preview/<?php echo $row['cat'];?>/<?php echo $row['previewfile'];?>"height="170" width="150"/>

I want to know that what code should be placed on final download page to call the clicked content (from download page)in that.

cffrost2




msg:4440122
 5:54 pm on Apr 12, 2012 (gmt 0)

So a visitor is on your "download Page", clicks a link that then takes them to the "final download page" where you need to render the selection for download. Correct? Set a variable in the link and fetch it on the final download page and use it to fetch the data from the database.

<a href="folder/subfolder/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>?fileid=<?php echo $row['id']; ?>"><?php echo $row['title'];?></a>
//then on the "final download page, get the fileid and use it to query you db
if(isset($_REQUEST['linkid']) && !empty($_REQUEST['linkid']))
{
//query mysql
}
else
{
//handle error
}

Is this what you needed?

neo2sxn




msg:4440188
 8:26 pm on Apr 12, 2012 (gmt 0)

Thanks for reply cffrost2,
you got me right but in this line "fileid=<?php echo $row['id'];" i can not use "id"
because i am calling the sub folders like "sub_category" , "cat" in the <a href=""> tag from different tables.

cffrost2




msg:4440258
 11:43 pm on Apr 12, 2012 (gmt 0)

My thought is that you would just have a direct link straight to the download when the user clicks the link from the preview page but I'm gathering you instead have them go to a page like download.php with a link to click to start downloading. Seems like an extra step.

Could you use the variables you have already set in the clicked link? such as $row['sub_category'], $row['cat'] and $row['file'] to get what you need from the database to render on the final download page?

<a href="folder/subfolder/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>?sub_category=<?php echo $row['sub_category']; ?>&cat=<?php echo $row['cat']; ?>&file=<?php echo $row['file']; ?>"><?php echo $row['title'];?></a>
//then on the "final download page, get the variables and use them to query you db
if(isset($_REQUEST['file']) && !empty($_REQUEST['file']))
{
//query mysql
//then build the click here to start your download link
}
else
{
//handle error
}

cffrost2




msg:4440259
 11:49 pm on Apr 12, 2012 (gmt 0)

Going back to this,

eelixduppy,

Yes my html looks like -
<a href="folder/subfolder/subcategory/Software/category/file.pdf">title goes here</a>

After interpreted by php .and my file is stored in the location described by <a ref=""> link.

And yes i want final download page to fetch this content and offer it to download to the user?

It seems to me once the user clicks on the <a href> link, the download would automatically start, correct?

neo2sxn




msg:4440340
 5:02 am on Apr 13, 2012 (gmt 0)


Thans for reply cffrost2,

no,i don't want to start direct download from preview page(product page),i want that the download should start from final download page.

Ok let me start again -

I have two page
(1) Product page (where i am calling all the products with there links by a loop)
(2) Final download page (where i am calling the clicked content with downloading link)

Example - A user came to produtct page where all the product are placed with there own link.I am using a loop to call all the product on the product page..When a user clicks on the link he should come to final download page where the clicked product should show whith its download link.
But dont know how to fetch clicked content to final download page.

this is the loop which i am using on product page to show all the product -

<div class="cart_products">

<?php
$i=0;
$sql="select * from software";
$result=mysql_query($sql) or die(Error);
while($row=mysql_fetch_array($result))
{
if($i%3==0)
{
echo "</tr><tr>";
}
?>

*//Image Previews //*
<img src="upload/1/<?php echo $row['sub_category'];?>/Software/preview/<?php echo $row['cat'];?>/<?php echo $row['previewfile'];?>"height="170" width="150"/>

//Links (its strting direct download instead of sending user to final download page)//
<a href="upload/1/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>">CLICK HERE</a>
</div>
<?php $i++; } ?>


In the 'file' table we are storing the name of the file . Example - somefile.jar
In the 'previewfile' table we are storing the name of the preview image name. Example - somepreview.jpg

cffrost2




msg:4440548
 4:33 pm on Apr 13, 2012 (gmt 0)

Sorry I'm not able to help you fix your problem. Maybe one of these pro's here can jump in and give you some ideas. The only thing I can think to tell you is change the way it's setting up the link. I'm sure you have a download page. Something like download.php. So your php rendered link may need to be something along the lines of this

//Render this link for them to click and go straight to your final download page.
<a href="finaldownloadpage.php?link=upload/1/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>">CLICK HERE</a>

//then on the final download page, get the link and offer it to download
if(isset($_REQUEST['link']) && !1empty($_REQUEST['link']))
{ ?>
<a href="upload/1/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>">Click here to start your download</a>
<?php } else { //error } ?>

Then the user clicks the link, it takes them directly to your final download page where the link is called and offered for download. Sorry I couldn't assist more.

neo2sxn




msg:4440737
 4:04 am on Apr 14, 2012 (gmt 0)

Thank cffrost2,

O.k Now your coding is closer to the solution.
I placed this code to product.php


<a href="finaldownload.php?link=upload/1/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>">Click Here</a>


And placed this codes after editing -


<?php
@$link = $_GET['link'];

?>
<?php
//then on the final download page, get the link and offer it to download
if(isset($_REQUEST['link']) && !empty($_REQUEST['link']))
{ ?>
<a href="<?php echo $link['link'];?>">Click here to Download</a>
<?php
} ?>

I edit you finaldownloadpage.php codes because when i place this

<a href="upload/1/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>"><?php echo $row['title'];?></a>

Then it calls the content it self because it a complete path of the file itself.You kow what i want to say.

So i replace it with -


if(isset($_REQUEST['link']) && !empty($_REQUEST['link']))
{ ?>

<a href="<?php echo $link['link'];?>">hi</a>

<?php
} ?>

But now only a little problem, the finaldownloadpage.php is reading only first charector of fetched URL

Example - yourdomain.com/u

'u' is the first charecter of Upload folder which is in fetched url from productpage.php

<a href="finaldownload.php?link=upload/1/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>"><?php echo $row['title'];?></a>

neo2sxn




msg:4440786
 9:24 am on Apr 14, 2012 (gmt 0)

cffrost2,

I got the solution by your help.
I placed this code to Productpage.php -


<a href="finaldownload.php?link=upload/1/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>&Lname=upload/1/<?php echo $row['sub_category'];?>/Software/preview/<?php echo $row['cat'];?>/<?php echo $row['previewfile'];?>">CLICK HERE</a>

(&Lname is to call image preview in finaldownloadpage.php)

Then I placed this code to Finaldownloadpage.php -

<?php
@$link = $_GET['link'];
$url = "$link";

@$name = $_GET['Lname'];
$my ="$name";

?>
<a href="<?php echo $url ?>">Click Here To Download</a>
<img src="<?php echo $my ?>">


I have now only a little problem, URL is very long in URL bar when i redirected to Finaldownloadpage.php Something like this -

mediashareing.com/finaldownload.php?link=upload/1/N95/Software/Audio-Video/56927_facebook-new.jar&Lname=upload/1/N95/Software/preview/Audio-Video/70895_facebook-new.png

Is there any way to trim it ?

eelixduppy




msg:4440832
 12:34 pm on Apr 14, 2012 (gmt 0)

Ideally, you would have your products in a database of sorts. In this database, you would have a unique identifier for each product, with that products associated information (including, for example, where you can find its images, downloadable content, etc). It is this that you would use for identification on all of these pages.

So, for example, on your product page it would look something like this:


$i=0;
// note: you should probably use pagination here
$sql = "select * from software";
$result = mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result))
{
if($i++%3==0)
echo "</tr><tr>";
echo '<td>';
printf('<img src="image.php?pid=%s" height="170" width="150"/>', $row['pid']);
printf('<a href="product.php?pid=$s">CLICK HERE</a>', $row['pid'];
echo '</td>';
}


Where of course pid is the product ID. Now here there are two pages, image.php which fetches the image, and product.php, which lists additional information about the product.




So then, on the product.php page it would work something like this:


//assert pid is an integer
if(!preg_match('/^[0-9]+$/',$_GET['pid'])) {
echo 'Must have integer pid!';
exit;
}

// select info from database
$link = mysql_connect('..','..','..');

$query = sprintf("SELECT * FROM software WHERE pid = %s", $pid);
$result = mysql_query($query) or die(mysql_error());
if($row = mysql_fetch_array($result)) {
// print all the product information, including...
printf('<a href="download.php?pid=%s">Download!</a>', $pid);
}
mysql_close($link);





Now this piece introduces a download.php script. Up until not I've skipped the image.php script because it will work very similar to how the download script will work. I'm not going to be writing a complete script here and these can get complex some times depending on how you have everything set up, but the general idea is this:


// look up data in database using $_GET['pid']
// as in previous example
// this data should include where to find the image/download
// content on your box, lets say this gets set as...
$image_location = $row['previewimage'];


Now right here, it is necessarily to know what filetype your image/download is going to be. For example, if all your images are going to be jpegs, we can skip trying to identify what image type it is. If you want to handle multiple types (which is normally the case), you will first need to figure out the extension on the file you want to present, and then the respective MIME content type. So for a jpeg image, it would be something like this:


header("Content-Type: image/jpeg");
header("Content-Length: " .(string)(filesize($image_location)) );

echo file_get_contents($image_location);


Here, we are setting the appropriate headers and then "printing" out the contents of the binary image file.




Now with all that said, to directly answer your question you do not have to pass any of the static content in the URL since it doesn't change. You only need to pass the variable stuff. So for example, some like this would work:


printf(
'<a href="finaldownload.php?sub_category=%scat=%sfile=%spreviewfile=%s">CLICK HERE</a>',
urlencode($row['sub_category'),
urlencode($row['cat']),
urlencode($row['file']),
urlencode($row['previewfile'])
);


Then this way, you can reconstruct the actual links on the "finaldownload.php" page.


Hope this helps, and I apologize in advance if these don't work directly after a copy-and-paste, I'm typing this on the fly.

Good luck

neo2sxn




msg:4440855
 2:19 pm on Apr 14, 2012 (gmt 0)

Very thanks eelixduppy,
its too much wonder for me that some body can write so many lines for just me to help,

But i am confused which coding is for which page.
And also


my table stucture is like this -



CREATE TABLE IF NOT EXISTS `software` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`search_category` varchar(255) NOT NULL,
`sub_category` varchar(255) NOT NULL,
`cat` varchar(255) NOT NULL,
`file` varchar(255) NOT NULL,
`previewfile` varbinary(255) NOT NULL,
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`version` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=29 ;



INSERT INTO `software` (`id`, `search_category`, `sub_category`, `cat`, `file`, `previewfile`, `title`, `description`, `version`) VALUES
(27, '1', 'N95', 'Audio-Video', '56927_facebook-new.jar', '70895_facebook-new.png', 'Facebook Software', 'hi', '1.1');





And data base name is "media" and table name is "software"

neo2sxn




msg:4440894
 6:24 pm on Apr 14, 2012 (gmt 0)

Thanks eelixduppy,

This is true that i have now got a complete solution of my problem , just because both of you guys !

This is my final solution -


This is the final coding of product.php-

<?php
$i=0;
$sql="select * from software";
$result=mysql_query($sql) or die(Error);
while($row=mysql_fetch_array($result))
{
if($i%3==0)
{
echo "</tr><tr>";
}
?>

<img src="upload/1/<?php echo $row['sub_category'];?>/Software/preview/<?php echo $row['cat'];?>/<?php echo $row['previewfile'];?>"height="170" width="150"/> <br />
<a href="don.php?link=<?php echo $row['id'];?>">Click Here</a>

<?php $i++; } ?>

And this is the final coding of finaldownloadpage.php -

<?php

$i=0;

$sql="select * from software where id='" . $_REQUEST['link'] . "'";
$result=mysql_query($sql) or die('Error');
while($row=mysql_fetch_array($result))
{
if($i%3==0)
{
echo "</tr><tr>";
}

?>
<img src="upload/1/<?php echo $row['sub_category'];?>/Software/preview/<?php echo $row['cat'];?>/<?php echo $row['previewfile'];?>"height="170" width="150"/>
<a href="upload/1/<?php echo $row['sub_category'];?>/Software/<?php echo $row['cat'];?>/<?php echo $row['file'];?>">Click Here to Download</a>
<?php $i++; } ?>

On product page i am just calling the image and a link including its row id, and then sending that row id to finaldownloadpage.php , then i am retrieving the clicked link id to finaldownloadpage.php and telling its loop that what content to show

Now when i click any product from product.php it send me to finaldownloadpage.php and shows only clicked content on it, the url in browser window looks now so short like - localhost/mediashareing/don.php?link=27

:)

neo2sxn




msg:4440910
 7:41 pm on Apr 14, 2012 (gmt 0)

eelixduppy,

I want to ask one question.
Right now on my product.php the products are showing like this -

1 2 3
4 5 6
7 8 9

this is because i am using a loop in it.
My question is ,how can i place a ad grid at place of '5'
Like -
1 2 3
3 ad 4
5 6 7

I tried it by style sheet but its not working.Actuly i need a blank <div> </div> where i can place my desire content or ad codes.

neo2sxn




msg:4441069
 3:20 pm on Apr 15, 2012 (gmt 0)

Please help me out guys

eelixduppy




msg:4441123
 8:40 pm on Apr 15, 2012 (gmt 0)


$ad_placement = 4; // starts at 0
$i = 0;

while($row = mysql_fetch_array($result)) {
if($i % 3 == 0) {
// print end/begin row
}

if($i == $ad_placement) {
// print ad
continue;
}

//print your other stuff
}

neo2sxn




msg:4441148
 10:55 pm on Apr 15, 2012 (gmt 0)

Hello eelixduppy,

I placed this code-
<?php include("include/db.php");?>
<?php
$ad_placement = 4; // starts at 0
$i = 0;
$sql="select * from software";
$result=mysql_query($sql) or die('Error');
while($row = mysql_fetch_array($result)) {
if($i % 3 == 0) {
// print end/begin row
}

if($i == $ad_placement) {
echo ('hi');
continue;
}
?>

<img src="upload/1/<?php echo $row['sub_category'];?>/Software/preview/<?php echo $row['cat'];?>/<?php echo $row['previewfile'];?>"height="170" width="150"/>

<?php
}
?>

But its printing all the image continually but not printing advertisement on 5 position, Please correct this if i am doing something wrong

eelixduppy




msg:4441163
 11:33 pm on Apr 15, 2012 (gmt 0)

make sure to add 1 to $i at the end of the loop"


$i++;

neo2sxn




msg:4441369
 9:40 am on Apr 16, 2012 (gmt 0)

Thaks eelixduppy,


O.K it is done,

Only a last question
Can i replete fetching add grid Like -

1 2 3
4 ad 6
7 8 9

10 11 12
13 ad 15
16 17 18

19 20 21
22 23 24
25 26 27

And so on...

neo2sxn




msg:4441389
 10:51 am on Apr 16, 2012 (gmt 0)

Sorry i mean i want to fetch and repeat ad grid on every 5 position like this -

1 2 3 4 ad 6 7 8 9 ad 11 12 13 14 ad and so on ....

eelixduppy




msg:4441449
 1:17 pm on Apr 16, 2012 (gmt 0)

Replace this:


$ad_placement = 5;


And this:


if($i % $ad_placement == 0) {


But are you understanding why all of this is working? I'd really like for you to learn the why instead of having others write the code for you.

neo2sxn




msg:4441450
 1:18 pm on Apr 16, 2012 (gmt 0)

Hello,


My problem is solved , thank for giving me idea.

System
redhat



msg:4442436
 11:54 am on Apr 18, 2012 (gmt 0)

The following message was cut out to new thread by eelixduppy. New thread at: php/4442434.htm [webmasterworld.com]
7:37 am on Apr 18, 2012 (est -5)

System
redhat



msg:4444056
 7:52 am on Apr 21, 2012 (gmt 0)

The following message was cut out to new thread by eelixduppy. New thread at: php/4444054.htm [webmasterworld.com]
8:20 pm on Apr 22, 2012 (est -5)

neo2sxn




msg:4452199
 11:38 am on May 11, 2012 (gmt 0)

Hello Guys!

can somebody help me please ? This is my coding --

<?php
$uname=$_GET['mid']; //getting username
$query = mysql_query("SELECT friends FROM users WHERE user_name='$uname'");
while($row = mysql_fetch_array($query)) {
if($row["friends"]=="")
{echo "<div style='margin:17px 0px 15px 35px;color:#ce0100;'>This user do not have any friends yet.</div>";}
$friends = unserialize($row["friends"]); //unserialize the records
if(isset($friends[0])) {
foreach($friends as $friend) {
$_query = mysql_query("SELECT * FROM users WHERE id = '" . $friend . "'");
$_row = mysql_fetch_array($_query);
$frname=$_row["user_name"];
$frpic=$_row["upic"];
?>
<a href="user.php?mid=<?php echo $frname;?>"><img src="img/<?php echo $frpic;?>" class="imag"></a>&nbsp;&nbsp;&nbsp;&nbsp;
<?php
}
}
}
?>


I have two problems .

1) I am not able to use mysql_num_rows from second query , i mean when this coding runs,it shows three records (three picture along whith hyperlink).But i also want to print it in number formate like - "3" .
2) I am not able to sort or limit the records because in "user" table the row "friends" have serialize records like "{i:0;s:1:"2";i:1;s:1:"4";i:2;s:1:"3";}", as you can see in coding where i am unserialize them. I tried to put ORDER BY and LIMIT ,but those not works...

Please guys help me out to sort this problem..

Thanks in advance..

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved