Your Ad Here Your Ad Here
Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Call Data From Mysql ...

  1. #1
    TRshady
    Guest
    Hey all ... have been trying to for ages but simply cant get it....

    all I want to do is have a mysql table like this:

    section ---- title ---------------------------- content ------

    guides ----- improve performance ----[long text]


    and then be able to call it into pages ......
    anyone able to give me a little tut to do this please?

  2. Internet, Programming and Graphics   -   #2
    true_neo's Avatar The Dark Lord Revan
    Join Date
    Mar 2003
    Location
    Norway
    Age
    31
    Posts
    383
    Well.
    I got a teensy weensy bit of sql experience after pissing about with forums all the time, so heres something that MIGHT woik:

    $dbh=mysql_connect ("[your host, usually localhost]", "[database username", "[database password]");
    mysql_select_db ("[database name]");

    After you made your table in the base with something like
    mysql_query ("CREATE TABLE '[table name]' ('[rowname]' varchar([number of charas in your text]) DEFAULT'[default value]' NOT NULL) TYPE=MyISAM;");

    To fetch the data:
    mysql_query ("SELECT * FROM '[table name]' WHERE [info]='$var'");

    this is from within a php script
    for safety reasons, do not keep your passwords in such a file public


    O and when you replace my [things] with your actual info, take the [] away as well.
    any more questions/errors, then talk back and Ill do my best.
    //out
    Sage goes in the signature field.

  3. Internet, Programming and Graphics   -   #3
    phpmyadmin?
    <span style='color:black'> I am a part of all that I have met - Lord Tennyson</span>
    <span style='color:blue'>Try not to let your mind wander...it is too small and fragile to be out by itself</span>

  4. Internet, Programming and Graphics   -   #4
    Poster
    Join Date
    Oct 2003
    Location
    Montevideo,Uruguay
    Posts
    989
    phpmyadmin es just a way to make mysql commands easyier to do

  5. Internet, Programming and Graphics   -   #5
    TRshady
    Guest
    I do have phpmyadmin .. and am able to use it. I just dont have a clue how people go about calling that data to pages and whats the best way to go about doing it ...

  6. Internet, Programming and Graphics   -   #6
    Poster
    Join Date
    Jan 2003
    Location
    Belle Vernon, PA, USA
    Posts
    644
    Generic PHP code...
    Code:
    &#036;link = mysql_connect&#40;&#39;server&#39;, &#39;username&#39;, &#39;password&#39;&#41;;
    mysql_select_db&#40;&#39;database&#39;&#41;;
    
    &#036;result = mysql_query&#40;&#39;SELECT * FROM table&#39;&#41;;
    while &#40;&#036;row = mysql_fetch_assoc&#40;&#036;result&#41;&#41; {
     &nbsp; &nbsp;echo &#39;Field 1&#58; &#39;.&#036;row&#91;&#39;field1&#39;&#93;.&#39;&#60;br /&#62;&#39;.
     &nbsp; &nbsp; &nbsp; &nbsp; &#39;Field 2&#58; &#39;.&#036;row&#91;&#39;field2&#39;&#93;.&#39;&#60;br /&#62;&#39;.
     &nbsp; &nbsp; &nbsp; &nbsp; &#39;Field 3&#58; &#39;.&#036;row&#91;&#39;field3&#39;&#93;.&#39;&#60;br /&#62;&#39;;
    }

  7. Internet, Programming and Graphics   -   #7
    TRshady
    Guest
    Seems pretty straight forward ... but even simple scripts can confuse me if I dont fully understand it ... care to give a brief explanation on how to use that script with a ready made mysql table please?

    Cheers.

  8. Internet, Programming and Graphics   -   #8
    This isnt so hard and there are plently of tutorials on how to do this ill give you a quick guide and you can fire some questions back at us. However true_neo has got you started already so you should have replied to his post.

    If phpmyadmin is installed then making your table is simple and im expecting you to have at least done that.

    Easiest way to call the data and show it is to use a mixture of PHP and MySQL.

    Firstly you have to connect to the database

    <?php

    &#036;db = mysql_connect("localhost", "username", "password");
    mysql_select_db ("database name");

    /* This is a comment tag and it wont show on your page. Now you need to fetch the data. Seing as I dont understand what im fetching because your description of your table is vague here is one way of fetching data and outputting it */

    &#036;result = mysql_query("select * from table");
    while(&#036;r=mysql_fetch_array(&#036;result)) {
    &#036;section = &#036;r[section];
    &#036;title = &#036;r[title];
    &#036;content = &#036;r[content];

    /* Presuming the 3 title&#39;s: Section, title and content were colum headings and you have rows of data underneath them then this would fetch every row of data under those headings. the next part will print the data to the page and stop the query */

    echo &#036;section;
    echo &#036;title;
    echo &#036;content;

    } // <--that character ending the query

    ?> <--and this closed PHP

    All the variables in BOLD is data im assuming you know. What I have written above doesnt show off my great coding practice but it should work all the same.

    When you save the document make sure you save it as filename.php so it gets parsed through a PHP parser.

  9. Internet, Programming and Graphics   -   #9
    TRshady
    Guest
    Thank you very much for the reply&#33; ....
    Its so helpful and Ive actually managed to understand and follow it&#33;

    So I used this code:

    <?php

    &#036;db = mysql_connect("localhost", "triley_test", "test");
    mysql_select_db ("triley_content");

    &#036;result = mysql_query("select * from software");
    while(&#036;r=mysql_fetch_array(&#036;result)) {
    &#036;section = &#036;r[section];
    &#036;title = &#036;r[title];
    &#036;content = &#036;r[content];

    /* Presuming the 3 title&#39;s: Section, title and content were colum headings and you have rows of data underneath them then this would fetch every row of data under those headings. the next part will print the data to the page and stop the query */

    &#036;txt="
    ";

    echo &#036;section;
    echo &#036;txt;
    echo &#036;title;
    echo &#036;txt;
    echo &#036;content;

    }

    ?>
    and the result is this, which is exactly what I wanted. But now I have done this .. I have a few questions I hope can be answered.

    1. How do I go about formatting?
    - I assume is would be best to use css right?
    - or would I add tags to the text in the db?

    2. How would I use this?
    - for example I have a link to a &#39;blubster review&#39;, would I need to create a page similar to the code above for it and link to that page? .. or is there a more efficient way of doing this. Maybe having one page which gets variables in the url and loads a page?

    3. How can I make entered data keep current formatting?
    - I placed a page of text, being a guide into the table, and when viewed appears right with all the seperate paragraphs, breaks etc .. but when called into a page .. appears as on block .. any way to corrent this?

    I&#39;ll have more, but for now I&#39;d be really happy if these could be answered.
    Thanks again for being so helpful&#33;

  10. Internet, Programming and Graphics   -   #10
    It would be best if you use css and a generic build.php. That build.php is your normal template of the whole website. So in your index.php load build.php and u can do the same in other pages too.

    Your css file contains how the headers will look like and the various div&#39;s so to speak. Use print to display the values on the page.

    So all you are doing in actual pages are calling build.php for the template, calling css for all the styles, and then calling text from database and printing them using the styles.

    I know I am being more conceptual than giving you the actual code. But I am sure you can do it...

    Edit: oh by the way you dont need to have all the pages as this. You can include a function in build.php that gets the docname from the database. Also, use DIV&#39;s a lot. Will expand on this later, gotta go & catch on some sleep
    <span style='color:black'> I am a part of all that I have met - Lord Tennyson</span>
    <span style='color:blue'>Try not to let your mind wander...it is too small and fragile to be out by itself</span>

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •