Jump to content

Recommended Posts

This is what I have so far...

 

language.php

 

<?php
session_start();
$con = mysql_connect("sql09.freemysql.net","adamlr14","");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$language = 'en';
echo mysql_error();

mysql_select_db("language", $con);

if(!mysql_select_db("language", $con))
  {
  die('Could not select db: ' . mysql_error());
  }

$result = mysql_query("SELECT * FROM en");

$row = mysql_fetch_array($result);
echo mysql_error();


?>

 

example of database 

 

ref                                                                     text       

1                                                  Welcom this site is in construction!

2                                                  Please login before you continue!

 

 

Now the bit I want to do now is 'require' the page and echo for example

$row[text]

were

$row[ref] = "1"

 

Sorry if it is confusing

Link to comment
https://forums.phpfreaks.com/topic/208853-how-can-this-be-done/
Share on other sites

Now the bit I want to do now is 'require' the page

Require what page?

 

The aim of this file is to pull the 'text' from the database and the requiring page would show it example of the file requiring language.php

 

adam.php

 

<?php

require("language.php");

echo {the bit I cannot do} {echo $row[text] were $row[ref] = 1 }

?>

 

I would like it to echo            Welcom this site is in construction!

You'll need to use an MySQL query first. Really basic example

$sql = 'SELECT text FROM en WHERE ref=1';
$result = mysql_query($sql);
if($result) {
    list($lang_text) = mysql_fetch_row($result)
    echo "<b>$lang_text</b>";
} else {
    echo 'Cannot find language text';
}

However you wouldn't want to do that for every bit of text you want to output.

 

Instead you'll be better of getting all the text from the database first

$sql = 'SELECT ref, text FROM en';
$result = mysql_query($sql);
if($result) {
    while($row = mysql_fetch_row($result)) {
         list($id, $text) = mysql_fetch_row($result);
         $lang[$id] = $text;
    }
}

 

Now for each bit of text you want you'll just echo out the nesseccary variable ([ tt]echo $lang[ref id]; ), eg

echo $lang[1] . '<br />' . $lang[2];

Now this is my code ...

 

language.php

 

<?php
session_start();
$con = mysql_connect("sql09.freemysql.net","adamlr14","");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

echo mysql_error();

mysql_select_db("language", $con);

if(!mysql_select_db("language", $con))
  {
  die('Could not select db: ' . mysql_error());
  }

$sql = 'SELECT ref, text FROM en';
$result = mysql_query($sql);
if($result) {
    while($row = mysql_fetch_row($result)) {
         list($id, $text) = mysql_fetch_row($result);
         $lang[$id] = $text;
    }
}
print_r($lang);
echo mysql_error();
?>

 

The problem is is that if you try to pull an odd number for example $lang[3] it echos nothing but if you change it to even number $lang[2] it echo what it should ....... I used print_r(lang) and it only has even numbers ???????

 

print_r($lang)

 

Array ( [2] => try2 [4] => try4 [6] => try6 )  

 

 

database

 

ref                                            text

1                                                try1

2                                                try2

3                                                try3

4                                                try4

5                                                try5

6                                                try6

 

 

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.