Jump to content

how do i create .php pages with code based upon a data base of data? more below


scbookz

Recommended Posts

a)i have a list of  numbers lets say 10,000

b)i have a function and php code for each number to pull from an html page

 

c)i want to duplicate b) for 10,000 numbers so i have 10,000 pages

on the server

------------

i will have

------------------

1.php

2.php

3.php

4.php  10,000 times, and each  page will have the same code, except for one line in  each page that corresponds to the number  1 2 3 4  respectively

Link to comment
Share on other sites

[function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections in /var/www/osc/osc/osc/marksfolder/guess.php on line 7

 

i cant even open one file much less 10,000

 

i tried to create a file with a .php  file and it  gave that error

here is my code

---------------------------------------------

<?php

 

 

$ourFileName = "http://xx.xx.xx.xx:81/osc/osc/osc/marksfolder/044651652X.php";

$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");

fclose($ourFileHandle);

?>

 

i did a changemod 777

so it is writeable in that directory

maybe i need to change all directories backwards

Link to comment
Share on other sites

?

 

Reply Quote

Xian

Re: HTTP wrapper does not support writeable connections

five years ago

To try Larry's suggestion, I *think* you would just need to replace $homedirectory with $_SERVER['DOCUMENT_ROOT'] OR possibly realpath($_SERVER['DOCUMENT_ROOT']).

 

Reply Quote

Link to comment
Share on other sites

ok that worked this code works but no content was created just an empty file

 

<?php

 

 

$ourFileName = "044651652X.php";

$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");

fclose($ourFileHandle);

?>

 

-------

how do i add content automatically?

Link to comment
Share on other sites

will this work?

 

<?

$body_content="This is my content"; // Store some text to enter inside the file

$file_name="test_file.txt";              // file name

$fp = fopen ($file_name, "w");

// Open the file in write mode, if file does not exist then it will be created.

fwrite ($fp,$body_content);          // entering data to the file

fclose ($fp);                                // closing the file pointer

chmod($file_name,0777);          // changing the file permission.

?>

Link to comment
Share on other sites

why don't you just create on template php page with certain places for different data to fill in certain spaces. Then just query the database using an id number like yoursite.com/whatever.php?id=3.

 

then your template(whatever.php) will have the information with what your query the database with that number.

 

that way you have ONE page with limitless possibilities of data filling in the gaps. Thats the basic theory with websites that have have a gigabillion different "pages"

Link to comment
Share on other sites

ok....make your html page with places for data. For this example ill just use a basic table with person's info. so we have

 

<table>
<tr><td>Name:</d>     <td>?</td>   </tr>
<tr><td>Gender:</d>   <td>?</td>   </tr>
<tr><td>State:</d>     <td>?</td>   </tr>
</table>

 

and we want a "page" for each person in our database. Well, we'll just replace those three question marks with actual data. So...save this template page as "template.php" or something like that. Now our actual url will end up looking like this "www.yoursite.com/template.php?id=32". What this is saying is go to the template page but use the person whoever has the ID of 32 to fill out the information.

 

So the php would look something similar to this.

 

<?php
$id_number = $_GET['id'];//this will get that id number out of the url

//then connect to the database
$cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect");

//then write a simple query that will pull up the person's info based on that id number
$query = "SELECT * FROM your_table WHERE id_number = '$id_number'";
//run the query
$result = mysqli_query($cxn,$query)
               or die("Couldn't execute select query.");
//assign the results to a variable
$row = mysqli_fetch_assoc($result);

 

now we go back and add places to insert the data we just pulled up...so go to edit template.php

<table>
<tr><td>Name:</d>     <td><?php echo $row['name']; ?></td>   </tr>
<tr><td>Gender:</d>   <td><?php echo $row['gender']; ?></td>   </tr>
<tr><td>State:</d>     <td><?php echo $row['state']; ?></td>   </tr>
</table>

 

now...put the php we just wrote at the very top of your html page like so

<?php
$id_number = $_GET['id'];//this will get that id number out of the variable

//then connect to the database
$cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect");

//then write a simple query that will pull up the person's info based on that id number
$query = "SELECT * FROM your_table WHERE id_number = '$id_number'";
//run the query
$result = mysqli_query($cxn,$query)
               or die("Couldn't execute select query.");
//assign the results to a variable
$row = mysqli_fetch_assoc($result);
?>
<html>
<head></head>
<body>
<table>
<tr><td>Name:</d>     <td><?php echo $row['name']; ?></td>   </tr>
<tr><td>Gender:</d>   <td><?php echo $row['gender']; ?></td>   </tr>
<tr><td>State:</d>     <td><?php echo $row['state']; ?></td>   </tr>
</table>
</body>
</html>

 

save that as template.php and put it in a directory and go to www.yoursite.com/template.php?id=23.. This script will grab all the info associated with the number 23.

 

NOTE: this assumes your table is called "your_table" and you have fields in the table labeled "name", "gender", "id_number", and "state"

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.