Jump to content

Help need for coding complicated php script


Ramamoorthy
Go to solution Solved by cyberRobot,

Recommended Posts

Hi all,

I am coding for Windows software download website - there I ll be having more than 300 softwares .

every category will be having its unique ID , every software will be having its unique ID, every software version will be having its unique ID.

Example :

For category Browser  : id will be  bro

for software chrome :  id will be bro_aaaa

for chrome 28.0   : id will be bro_aaaa_aa

 

here how I ll print the informations in website 

// db.php //

 

$bro = "Browsers";

$bro_aaaa = "Google Chrome";

$bro_aaaa_aa = "28.0"

 

-----(end of file db.php)

 

// include.php  //

 

<?php

echo $softwarecat;

echo $softwarename;

echo $softwareversion;

?>

---------(end of file include.php)

// software-page.php //

<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/db.php');

 

$softwarecat =$bro;

$softwarename =$bro_aaaa;

$softwareversion =$bro_aaaa_aa;

 

include './include.php'; 

 

?>

/* using include.php because just changing only this file , I can implement changes all over the website */

 

so the server will print everything rightly as mentioned in the db.php

 

Now .

if I change the include.php as like below .

 

<?php

echo $softwarecat;

echo $softwarename;

echo $softwareversion;

echo $softwaresize; /* listen - new feature */

?>

 

It will lead to error in all software pages as I haven't specified the value for $softwaresize . but I can specify it for new software pages .

 

How can I fix it .

Only way I know is below

 

in softwarepage.php

 

<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/db.php');

 

$softwarecat = bro;

$softwareid = aaaa;

$softwareversionid = aa;

 

include './include.php'; 

?>

 

now I need help for this part .

the server has to replace the $softwarecat as $bro; and $softwareid as aaaa; and $softwareversionid as aa;

if this happens I can completely change the include.php file as my wish .

 

any help is greatly appreciated . 

I am here to clarify any doubt regarding my question

 

(Note : I am very new to this site and I don't know how to even ask a question. anyone please guide)

Edited by Ramamoorthy
Link to comment
Share on other sites

Hi all,


I am coding for Windows software download website - there I ll be having more than 300 softwares .


every category will be having its unique ID , every software will be having its unique ID, every software version will be having its unique ID.


Example :


For category Browser  : id will be  bro


for software chrome :  id will be bro_aaaa


for chrome 28.0   : id will be bro_aaaa_aa


 


here how I ll print the informations in website 


// db.php //



<?php
$bro = "Browsers";
$bro_aaaa = "Google Chrome";
$bro_aaaa_aa = "28.0"
?>

-----(end of file db.php)


 


// include.php  //



<?php
echo $softwarecat;
echo $softwarename;
echo $softwareversion;
?>

---------(end of file include.php)


// software-page.php //



<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/db.php');

$softwarecat =$bro;
$softwarename =$bro_aaaa;
$softwareversion =$bro_aaaa_aa;

include './include.php'; 

?>

/* using include.php because just changing only this file , I can implement changes all over the website */


 


so the server will print everything rightly as mentioned in the db.php


 


Now .


if I change the include.php as like below .



<?php
echo $softwarecat;
echo $softwarename;
echo $softwareversion;
echo $softwaresize; /* listen - new feature */
?>

It will lead to error in all software pages as I haven't specified the value for $softwaresize . but I can specify it for new software pages .


 


How can I fix it .


Only way I know is below


 


in softwarepage.php



<?php
require_once($_SERVER['DOCUMENT_ROOT'] . '/db.php');

$softwarecat = bro;
$softwareid = aaaa;
$softwareversionid = aa;

include './include.php'; 
?>

now I need help for this part .


the server has to replace the $softwarecat as $bro; and $softwareid as aaaa; and $softwareversionid as aa;


if this happens I can completely change the include.php file as my wish .


 


any help is greatly appreciated . 


I am here to clarify any doubt regarding my question


 


(Note : I am very new to this site and I don't know how to even ask a question. anyone please guide)


please dont recommend to use mysql - I think it can be easily done . But I dont know mysql (even I know only very little php)


Link to comment
Share on other sites

 

Now .

if I change the include.php as like below .

<?php
echo $softwarecat;
echo $softwarename;
echo $softwareversion;
echo $softwaresize; /* listen - new feature */
?>

It will lead to error in all software pages as I haven't specified the value for $softwaresize . but I can specify it for new software pages .

You need top check if $softwaresize exists before using it. You can do this using the isset function

if(isset($softwaresize)) {
    // variable exists. We can use it with out error
    echo $softwaresize; /* listen - new feature */
}

Now It'll only echo out the $softwaresize variable  if it exists and wont display a notice error for undefined variable $softwaresize.

 

 

 

Only way I know is below

 

in softwarepage.php

<?php

require_once

($_SERVER['DOCUMENT_ROOT'] . '/db.php');

 

$softwarecat = bro;

$softwareid = aaaa;

$softwareversionid = aa;

 

include './include.php'; 

?>

now I need help for this part .

the server has to replace the $softwarecat as $bro; and $softwareid as aaaa; and $softwareversionid as aa;

if this happens I can completely change the include.php file as my wish .

That doesn't make any sense to me. Where is bro aaa and aa coming from?

Link to comment
Share on other sites

 

So basically, $softwaresize will be defined in some page, but not others? And you're looking to echo the value only when it's set? If so, you could try something like:

if(isset($softwaresize)) { echo $softwaresize; }

I am not sure that you entirely got my question . But I dont want to check whether the variable is declared or not  . I want to implement the feature all over the site ..

Link to comment
Share on other sites

I am not sure that you entirely got my question . But I dont want to check whether the variable is declared or not  . I want to implement the feature all over the site ..

 

The isset() function is just there as a stopgap. Once all of your pages have the variable defined before calling include.php, the isset() can be removed.

 

Is there other issues with the website if $softwaresize isn't set?

Link to comment
Share on other sites

This post could help more to the question.

I have 4 files 

db.php  - databse file

include.php  - global include file like header and footer

soft1.php - single php file for software listing

soft2.php - again single php file for software listing.

 

CODES

 

in db.php

<?php
$bro_aaaa= "google chrome"
$bro_aaaa_aa = "28.0"
?>

in include.php

<?php
echo $softwarename;
echo $softwareversion;
?>

in soft1.php

<?php
require './db.php';
$softwarename = $bro_aaaa;
$softwareversion = $bro_aaaa_aa;
include './include.php';
?>

so If I now change the Include.php for adding two more feature like this .

<?php
echo $softwarename;
echo $softwareversion;
echo $softwareversion_size;
echo $softwareversion_releasedate;
?>

and add new file to server called 

soft2.php

<?php
require './db.php';
$softwarename = $bro_aaaa;
$softwareversion = $bro_aaaa_aa;
$softwareversion_size = $bro_aaaa_aa_size;
$softwareversion_releasedate = $bro_aaaa_aa_reldate;

include './include.php';
?>

(I will add needed informations in the database - db.php)

 

now my soft1.php page will lead to error because it doesnt know what new 2 variables is .

but I dont want to use isset - and if it isset it have to show , otherwise it ll will not show the new2 feature .because I need to implement the feature for all softwares (all new and old pages)..

 

how can achieve new feature implementation throughout the site ..?

Link to comment
Share on other sites

The isset() function is just there as a stopgap. Once all of your pages have the variable defined before calling include.php, the isset() can be removed.

 

Is there other issues with the website if $softwaresize isn't set?

thanks for the idea. I can add the newly implemented variable .. only if I have some 100 or 200 pages ..

what If I have some thousands of page .

anyway I ll surely consider this , but man keep giving guidance to me .

Link to comment
Share on other sites

  • Solution

now my soft1.php page will lead to error because it doesnt know what new 2 variables is .

but I dont want to use isset - and if it isset it have to show , otherwise it ll will not show the new2 feature .because I need to implement the feature for all softwares (all new and old pages)..

 

how can achieve new feature implementation throughout the site ..?

 

Sorry, I'm not seeing the issue. When using the isset feature, the variable will display when it's set. It won't display (and won't give an error) when the variable isn't set. Perhaps I'm missing something. You might need to provide more information about the script and what you're trying to do.

 

 

thanks for the idea. I can add the newly implemented variable .. only if I have some 100 or 200 pages ..

what If I have some thousands of page .

anyway I ll surely consider this , but man keep giving guidance to me .

 

Do the pages work fine without the newly added feature? If so, then you can use the stopgap measure. If not, you should set up a development site; change everything (100 or 200 pages); then go live with the updated website.

 

While making the changes, you should consider if there is a better way to build the website. Are many of the pages coded similarly? If so, perhaps you could build a common script that's populated with information from a database.

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.